]> git.ipfire.org Git - thirdparty/strongswan.git/commitdiff
utils: ref_get() returns the new value of the reference counter
authorMartin Willi <martin@revosec.ch>
Wed, 8 May 2013 13:07:09 +0000 (15:07 +0200)
committerMartin Willi <martin@revosec.ch>
Thu, 9 May 2013 14:31:57 +0000 (16:31 +0200)
This allows us to use ref_get() for getting unique values.

src/libstrongswan/utils/utils.c
src/libstrongswan/utils/utils.h

index 2f38d8a9333104f322b9cdc43eeb35a1da0f3d27..1f30572ba291af1e0c60b4c5a41b59a954ab353d 100644 (file)
@@ -474,11 +474,15 @@ static pthread_mutex_t ref_mutex = PTHREAD_MUTEX_INITIALIZER;
 /**
  * Increase refcount
  */
-void ref_get(refcount_t *ref)
+refcount_t ref_get(refcount_t *ref)
 {
+       refcount_t current;
+
        pthread_mutex_lock(&ref_mutex);
-       (*ref)++;
+       current = ++(*ref);
        pthread_mutex_unlock(&ref_mutex);
+
+       return current;
 }
 
 /**
index c66c665e08cac6873563b71b15d89323d60b9497..13df036edf56878dea1102681dcd46c295b82677 100644 (file)
@@ -662,7 +662,7 @@ typedef volatile u_int refcount_t;
 
 #ifdef HAVE_GCC_ATOMIC_OPERATIONS
 
-#define ref_get(ref) {__sync_fetch_and_add(ref, 1); }
+#define ref_get(ref) __sync_add_and_fetch(ref, 1)
 #define ref_put(ref) (!__sync_sub_and_fetch(ref, 1))
 
 #define cas_bool(ptr, oldval, newval) \
@@ -678,8 +678,9 @@ typedef volatile u_int refcount_t;
  * Increments the reference counter atomic.
  *
  * @param ref  pointer to ref counter
+ * @return             new value of ref
  */
-void ref_get(refcount_t *ref);
+refcount_t ref_get(refcount_t *ref);
 
 /**
  * Put back a unused reference.