/* * Copyright (C) James R. Leu 2000 * jleu@mindspring.com * * This software is covered under the LGPL, for more * info check out http://www.gnu.org/copyleft/lgpl.html */ #ifndef _LDP_REFCNT_H_ #define _LDP_REFCNT_H_ #ifdef __LDP_LINUX__ #include "ldp_assert.h" #else #include #endif #define LDP_REFCNT_FIELD uint32_t _refcnt #define LDP_REFCNT_VALUE(obj) (obj)?((obj)->_refcnt):(-1) #define LDP_REFCNT_INIT(obj,count) { \ (obj)->_refcnt = count; \ } #define LDP_REFCNT_HOLD(obj) { \ if((obj) != NULL) { \ (obj)->_refcnt++; \ } \ } #define LDP_REFCNT_RELEASE(obj,dstry) { \ if((obj) != NULL) { \ (obj)->_refcnt--; \ if((obj)->_refcnt <= 0) { \ dstry(obj); \ obj = NULL; \ } \ } \ } #define LDP_REFCNT_ASSERT(obj,count) { \ if((obj) != NULL) { \ LDP_ASSERT((obj)->_refcnt == count); \ } \ } #define LDP_REFCNT_PTR_TYPE uint32_t* #define LDP_REFCNT_PTR(obj) (((obj) != NULL)?(&((obj)->_refcnt)):(NULL)) #define LDP_REFCNT_PTR_HOLD(ptr) { \ if((ptr) != NULL) { \ ((*(ptr))++); \ } \ } #define LDP_REFCNT_PTR_RELEASE(ptr) { \ if((ptr) != NULL) { \ ((*(ptr))--); \ } \ } #endif