1ca0551cfSopenharmony_ci/* 2ca0551cfSopenharmony_ci * Copyright (c) 2022 Huawei Device Co., Ltd. 3ca0551cfSopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License"); 4ca0551cfSopenharmony_ci * you may not use this file except in compliance with the License. 5ca0551cfSopenharmony_ci * You may obtain a copy of the License at 6ca0551cfSopenharmony_ci * 7ca0551cfSopenharmony_ci * http://www.apache.org/licenses/LICENSE-2.0 8ca0551cfSopenharmony_ci * 9ca0551cfSopenharmony_ci * Unless required by applicable law or agreed to in writing, software 10ca0551cfSopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS, 11ca0551cfSopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12ca0551cfSopenharmony_ci * See the License for the specific language governing permissions and 13ca0551cfSopenharmony_ci * limitations under the License. 14ca0551cfSopenharmony_ci */ 15ca0551cfSopenharmony_ci 16ca0551cfSopenharmony_ci#include "util/light_refcount_base.h" 17ca0551cfSopenharmony_ci 18ca0551cfSopenharmony_cinamespace OHOS { 19ca0551cfSopenharmony_cinamespace Idl { 20ca0551cfSopenharmony_ciint LightRefCountBase::AddRef() 21ca0551cfSopenharmony_ci{ 22ca0551cfSopenharmony_ci const int beforeCount = refCount_.fetch_add(1, std::memory_order_relaxed); 23ca0551cfSopenharmony_ci return beforeCount + 1; 24ca0551cfSopenharmony_ci} 25ca0551cfSopenharmony_ci 26ca0551cfSopenharmony_ciint LightRefCountBase::Release() 27ca0551cfSopenharmony_ci{ 28ca0551cfSopenharmony_ci if (refCount_ == 0) { 29ca0551cfSopenharmony_ci delete this; 30ca0551cfSopenharmony_ci return 0; 31ca0551cfSopenharmony_ci } 32ca0551cfSopenharmony_ci const int beforeCount = refCount_.fetch_sub(1, std::memory_order_release); 33ca0551cfSopenharmony_ci if (beforeCount - 1 == 0) { 34ca0551cfSopenharmony_ci delete this; 35ca0551cfSopenharmony_ci } 36ca0551cfSopenharmony_ci return beforeCount - 1; 37ca0551cfSopenharmony_ci} 38ca0551cfSopenharmony_ci} 39ca0551cfSopenharmony_ci} 40