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() : refCount_(0) {} 19 20 int AddRef(); 21 22 int Release(); 23 GetRefCount()24 inline int GetRefCount() const 25 { 26 return refCount_.load(std::memory_order_relaxed); 27 } 28 29 protected: 30 virtual ~LightRefCountBase() = default; 31 32 private: 33 std::atomic<int> refCount_; 34 }; 35 } // namespace HDI 36 } // namespace OHOS 37 38 #endif // OHOS_HDI_LIGHTREFCOUNTBASE_H