Clean up the FTN functions a bit. There is not reason to check for
[mpls-ldp-portable.git] / common / mpls_refcnt.h
blobbb4c680db8e32a9059d205e2b01c269f7592ffde
2 /*
3 * Copyright (C) James R. Leu 2002
4 * jleu@mindspring.com
6 * This software is covered under the LGPL, for more
7 * info check out http://www.gnu.org/copyleft/lgpl.html
8 */
10 #ifndef _MPLS_REFCNT_H_
11 #define _MPLS_REFCNT_H_
13 #include "mpls_assert.h"
15 #define MPLS_REFCNT_FIELD uint32_t _refcnt
17 #define MPLS_REFCNT_VALUE(obj) (obj)?((obj)->_refcnt):(-1)
19 #define MPLS_REFCNT_INIT(obj,count) { \
20 (obj)->_refcnt = count; \
23 #define MPLS_REFCNT_HOLD(obj) { \
24 if((obj) != NULL) { \
25 (obj)->_refcnt++; \
26 } \
29 #define MPLS_REFCNT_RELEASE(obj,dstry) { \
30 if((obj) != NULL) { \
31 (obj)->_refcnt--; \
32 if((obj)->_refcnt <= 0) { \
33 dstry(obj); \
34 obj = NULL; \
35 } \
36 } \
39 #define MPLS_REFCNT_ASSERT(obj,count) { \
40 if((obj) != NULL) { \
41 MPLS_ASSERT((obj)->_refcnt == count); \
42 } \
45 #define MPLS_REFCNT_PTR_TYPE uint32_t*
46 #define MPLS_REFCNT_PTR(obj) (((obj) != NULL)?(&((obj)->_refcnt)):(NULL))
48 #define MPLS_REFCNT_PTR_HOLD(ptr) { \
49 if((ptr) != NULL) { \
50 ((*(ptr))++); \
51 } \
53 #define MPLS_REFCNT_PTR_RELEASE(ptr) { \
54 if((ptr) != NULL) { \
55 ((*(ptr))--); \
56 } \
59 #endif