• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 #include "util/light_refcount_base.h"
10 
11 namespace OHOS {
12 namespace HDI {
AddRef()13 int LightRefCountBase::AddRef()
14 {
15     const int beforeCount = refCount_.fetch_add(1, std::memory_order_relaxed);
16     return beforeCount + 1;
17 }
18 
Release()19 int LightRefCountBase::Release()
20 {
21     const int beforeCount = refCount_.fetch_sub(1, std::memory_order_release);
22     if (beforeCount - 1 == 0) {
23         delete this;
24     }
25     return beforeCount - 1;
26 }
27 } // namespace HDI
28 } // namespace OHOS