utils: ref_get() returns the new value of the reference counter
This allows us to use ref_get() for getting unique values.
This commit is contained in:
@@ -466,11 +466,15 @@ static pthread_mutex_t ref_mutex = PTHREAD_MUTEX_INITIALIZER;
|
|||||||
/**
|
/**
|
||||||
* Increase refcount
|
* Increase refcount
|
||||||
*/
|
*/
|
||||||
void ref_get(refcount_t *ref)
|
refcount_t ref_get(refcount_t *ref)
|
||||||
{
|
{
|
||||||
|
refcount_t current;
|
||||||
|
|
||||||
pthread_mutex_lock(&ref_mutex);
|
pthread_mutex_lock(&ref_mutex);
|
||||||
(*ref)++;
|
current = ++(*ref);
|
||||||
pthread_mutex_unlock(&ref_mutex);
|
pthread_mutex_unlock(&ref_mutex);
|
||||||
|
|
||||||
|
return current;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -661,7 +661,7 @@ typedef volatile u_int refcount_t;
|
|||||||
|
|
||||||
#ifdef HAVE_GCC_ATOMIC_OPERATIONS
|
#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 ref_put(ref) (!__sync_sub_and_fetch(ref, 1))
|
||||||
|
|
||||||
#define cas_bool(ptr, oldval, newval) \
|
#define cas_bool(ptr, oldval, newval) \
|
||||||
@@ -677,8 +677,9 @@ typedef volatile u_int refcount_t;
|
|||||||
* Increments the reference counter atomic.
|
* Increments the reference counter atomic.
|
||||||
*
|
*
|
||||||
* @param ref pointer to ref counter
|
* @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.
|
* Put back a unused reference.
|
||||||
|
|||||||
Reference in New Issue
Block a user