aboutsummaryrefslogtreecommitdiffstats
path: root/src/libutil/ref.h
diff options
context:
space:
mode:
authorVsevolod Stakhov <vsevolod@highsecure.ru>2016-04-26 17:39:14 +0100
committerVsevolod Stakhov <vsevolod@highsecure.ru>2016-04-26 17:39:14 +0100
commit37f2f145165a1a89ee9838d1fd881e20145780e0 (patch)
tree57fd1497502fd237e69c4608e4dcaab133264684 /src/libutil/ref.h
parent7db64ece74622c7b5d079c0eb26118518a3dfd13 (diff)
downloadrspamd-37f2f145165a1a89ee9838d1fd881e20145780e0.tar.gz
rspamd-37f2f145165a1a89ee9838d1fd881e20145780e0.zip
[Feature] Add simplier versions of refcounts
Now REF_RETAIN and REF_RELEASE cannot be used for interprocess/interthreads refcounting. However, for a single process their performance should slightly increased. New REF_RETAIN_ATOMIC and REF_RELEASE_ATOMIC are implemented to replace old semantics.
Diffstat (limited to 'src/libutil/ref.h')
-rw-r--r--src/libutil/ref.h10
1 files changed, 7 insertions, 3 deletions
diff --git a/src/libutil/ref.h b/src/libutil/ref.h
index a70b9829b..1e2fc30b5 100644
--- a/src/libutil/ref.h
+++ b/src/libutil/ref.h
@@ -46,13 +46,13 @@ typedef struct ref_entry_s {
} while (0)
#ifdef HAVE_ATOMIC_BUILTINS
-#define REF_RETAIN(obj) do { \
+#define REF_RETAIN_ATOMIC(obj) do { \
if ((obj) != NULL) { \
__atomic_add_fetch (&(obj)->ref.refcount, 1, __ATOMIC_RELEASE); \
} \
} while (0)
-#define REF_RELEASE(obj) do { \
+#define REF_RELEASE_ATOMIC(obj) do { \
if ((obj) != NULL) { \
unsigned int _rc_priv = __atomic_sub_fetch (&(obj)->ref.refcount, 1, __ATOMIC_ACQ_REL); \
if (_rc_priv == 0 && (obj)->ref.dtor) { \
@@ -60,7 +60,12 @@ typedef struct ref_entry_s {
} \
} \
} while (0)
+
#else
+#define REF_RETAIN_ATOMIC REF_RETAIN
+#define REF_RELEASE_ATOMIC REF_RELEASE_ATOMIC
+#endif
+
#define REF_RETAIN(obj) do { \
if ((obj) != NULL) { \
(obj)->ref.refcount ++; \
@@ -74,6 +79,5 @@ typedef struct ref_entry_s {
} \
} \
} while (0)
-#endif
#endif /* REF_H_ */