/** * Copyright (c) Huawei Technologies Co., Ltd. 2023. All rights reserved. * 内部基础模块,所有参数合法性由调用者保证 */ #ifndef REF_OBJ_H_ #define REF_OBJ_H_ #include "c_base.h" #include "mmpa_api.h" #ifdef __cplusplus extern "C" { #endif typedef struct { mmAtomicType64 refCount; void *obj; } RefObj; typedef void* (*FnCreateRefObjValue)(RefObj *); typedef void* (*FnCreateRefObjValueWithUserData)(RefObj *, const void *); typedef void (*FnDestroyRefObjValue)(RefObj *); #define REF_OBJ_INIT {0, NULL} void InitRefObj(RefObj *obj); static inline void* GetRefObjVal(RefObj *obj) { return obj->obj; }; void* GetObjRef(RefObj *obj, FnCreateRefObjValue fnCreateObj); void* GetObjRefWithUserData(RefObj *obj, const void *userData, FnCreateRefObjValueWithUserData fnCreateObj); // 为了避免fnDestroyObj里面释放RefObj场景的,obj->obj的指针赋空的动作由fnDestroyObj函数执行保证 void ReleaseObjRef(RefObj *obj, FnDestroyRefObjValue fnDestroyObj); #ifdef __cplusplus } #endif #endif