summaryrefslogtreecommitdiffstats
path: root/src/libutil/ref.h
diff options
context:
space:
mode:
authorVsevolod Stakhov <vsevolod@highsecure.ru>2014-09-22 17:27:05 +0100
committerVsevolod Stakhov <vsevolod@highsecure.ru>2014-09-22 17:27:05 +0100
commit17e0a0778389ab4741747beb8cae5eedab0327a3 (patch)
tree8b1eecb667ce58959e750fddea81e5d9a712ef31 /src/libutil/ref.h
parent05a46b8f2181daf06170613ce382c0c7ba58c7ad (diff)
downloadrspamd-17e0a0778389ab4741747beb8cae5eedab0327a3.tar.gz
rspamd-17e0a0778389ab4741747beb8cae5eedab0327a3.zip
Implement the proper reset of HTTP messages.
Diffstat (limited to 'src/libutil/ref.h')
-rw-r--r--src/libutil/ref.h16
1 files changed, 14 insertions, 2 deletions
diff --git a/src/libutil/ref.h b/src/libutil/ref.h
index a8016b16d..8caab5c8f 100644
--- a/src/libutil/ref.h
+++ b/src/libutil/ref.h
@@ -36,35 +36,47 @@ typedef struct ref_entry_s {
} ref_entry_t;
#define REF_INIT(obj, dtor_cb) do { \
+ if ((obj) != NULL) { \
(obj)->ref.refcount = 0; \
(obj)->ref.dtor = (ref_dtor_cb_t)(dtor_cb); \
+ } \
} while (0)
#define REF_INIT_RETAIN(obj, dtor_cb) do { \
+ if ((obj) != NULL) { \
(obj)->ref.refcount = 1; \
(obj)->ref.dtor = (ref_dtor_cb_t)(dtor_cb); \
+ } \
} while (0)
#ifdef HAVE_ATOMIC_BUILTINS
#define REF_RETAIN(obj) do { \
+ if ((obj) != NULL) { \
__sync_add_and_fetch (&(obj)->ref.refcount, 1); \
+ } \
} while (0)
#define REF_RELEASE(obj) do { \
- unsigned int rc = __sync_sub_and_fetch (&(obj)->ref.refcount, 1); \
- if (rc == 0 && (obj)->ref.dtor) { \
+ if ((obj) != NULL) { \
+ unsigned int _rc_priv = __sync_sub_and_fetch (&(obj)->ref.refcount, 1); \
+ if (_rc_priv == 0 && (obj)->ref.dtor) { \
(obj)->ref.dtor (obj); \
} \
+ } \
} while (0)
#else
#define REF_RETAIN(obj) do { \
+ if ((obj) != NULL) { \
(obj)->ref.refcount ++; \
+ } \
} while (0)
#define REF_RELEASE(obj) do { \
+ if ((obj) != NULL) { \
if (--(obj)->ref.refcount == 0 && (obj)->ref.dtor) { \
(obj)->ref.dtor (obj); \
} \
+ } \
} while (0)
#endif