1 /* 2 * Copyright (c) 2020-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 HDF_SREF_H 10 #define HDF_SREF_H 11 12 #include "osal_atomic.h" 13 14 #ifdef __cplusplus 15 extern "C" { 16 #endif 17 18 struct HdfSRef; 19 20 struct IHdfSRefListener { 21 void (*OnFirstAcquire)(struct HdfSRef *); 22 void (*OnLastRelease)(struct HdfSRef *); 23 }; 24 25 struct HdfSRef { 26 OsalAtomic refs; 27 struct IHdfSRefListener *listener; 28 void (*Acquire)(struct HdfSRef *); 29 void (*Release)(struct HdfSRef *); 30 int (*Count)(const struct HdfSRef *); 31 }; 32 33 void HdfSRefAcquire(struct HdfSRef *sref); 34 void HdfSRefRelease(struct HdfSRef *sref); 35 int HdfSRefCount(const struct HdfSRef *sref); 36 void HdfSRefConstruct(struct HdfSRef *sref, struct IHdfSRefListener *listener); 37 38 #ifdef __cplusplus 39 } 40 #endif 41 42 #endif /* HDF_SREF_H */ 43