From: Vsevolod Stakhov Date: Tue, 26 Apr 2016 16:39:14 +0000 (+0100) Subject: [Feature] Add simplier versions of refcounts X-Git-Tag: 1.3.0~623 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=37f2f145165a1a89ee9838d1fd881e20145780e0;p=thirdparty%2Frspamd.git [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. --- diff --git a/src/libutil/ref.h b/src/libutil/ref.h index a70b9829b2..1e2fc30b5b 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_ */