No longer do we use the ifmgr to walk the addresses attached to this
[mpls-ldp-portable.git] / common / mpls_refcnt.h
blobec476f2586dd1d6e3645daf371e7485748408fc8
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_RELEASE2(global,obj,dstry) { \
40 if((obj) != NULL) { \
41 (obj)->_refcnt--; \
42 if((obj)->_refcnt <= 0) { \
43 dstry(global,obj); \
44 obj = NULL; \
45 } \
46 } \
49 #define MPLS_REFCNT_ASSERT(obj,count) { \
50 if((obj) != NULL) { \
51 MPLS_ASSERT((obj)->_refcnt == count); \
52 } \
55 #define MPLS_REFCNT_PTR_TYPE uint32_t*
56 #define MPLS_REFCNT_PTR(obj) (((obj) != NULL)?(&((obj)->_refcnt)):(NULL))
58 #define MPLS_REFCNT_PTR_HOLD(ptr) { \
59 if((ptr) != NULL) { \
60 ((*(ptr))++); \
61 } \
63 #define MPLS_REFCNT_PTR_RELEASE(ptr) { \
64 if((ptr) != NULL) { \
65 ((*(ptr))--); \
66 } \
69 #endif