1 /* 2 * Copyright (c) 2021 Huawei Device Co., Ltd. 3 * 4 * HDF is dual licensed: you can use it either under the terms of 5 * the GPL, or the BSD license, at your option. 6 * See the LICENSE file in the root of this repository for complete details. 7 */ 8 9 #ifndef OHOS_HDI_LIGHTREFCOUNTBASE_H 10 #define OHOS_HDI_LIGHTREFCOUNTBASE_H 11 12 #include <atomic> 13 14 namespace OHOS { 15 namespace HDI { 16 class LightRefCountBase { 17 public: LightRefCountBase()18 inline LightRefCountBase() 19 : refCount_(0) 20 {} 21 22 int AddRef(); 23 24 int Release(); 25 GetRefCount()26 inline int GetRefCount() const 27 { 28 return refCount_.load(std::memory_order_relaxed); 29 } 30 31 protected: ~LightRefCountBase()32 inline virtual ~LightRefCountBase() 33 {} 34 35 private: 36 std::atomic<int> refCount_; 37 }; 38 } // namespace HDI 39 } // namespace OHOS 40 41 #endif // OHOS_HDI_LIGHTREFCOUNTBASE_H