rx: Implement rx_atomic_dec_and_read

Add a function which decrements an atomic counter, and returns the
result. This is essential for implementing reference counting.

Change-Id: Ib173f078bcf117369a82f981d58124018648a71c
Reviewed-on: http://gerrit.openafs.org/3581
Reviewed-by: Jeffrey Altman <jaltman@openafs.org>
Tested-by: Jeffrey Altman <jaltman@openafs.org>
This commit is contained in:
Simon Wilkinson 2010-12-16 11:36:43 +00:00 committed by Jeffrey Altman
parent 50b1c161e8
commit b114faf52f

View File

@ -62,6 +62,11 @@ rx_atomic_dec(rx_atomic_t *atomic) {
InterlockedDecrement(&atomic->var);
}
static_inline int
rx_atomic_dec_and_read(rx_atomic_t *atomic) {
return InterlockedDecrement(&atomic->var);
}
static_inline void
rx_atomic_sub(rx_atomic_t *atomic, int change) {
InterlockedExchangeAdd(&atomic->var, 0 - change);
@ -110,6 +115,11 @@ rx_atomic_dec(rx_atomic_t *atomic) {
OSAtomicDecrement32(&atomic->var);
}
static_inline int
rx_atomic_dec_and_read(rx_atomic_t *atomic) {
return OSAtomicDecrement32(&atomic->var);
}
static_inline void
rx_atomic_sub(rx_atomic_t *atomic, int change) {
OSAtomicAdd32(0 - change, &atomic->var);
@ -165,6 +175,11 @@ rx_atomic_dec(rx_atomic_t *atomic) {
atomic_dec_32(&atomic->var);
}
static_inline int
rx_atomic_dec_and_read(rx_atomic_t *atomic) {
return atomic_dec_32_nv(&atomic->var);
}
static_inline void
rx_atomic_sub(rx_atomic_t *atomic, int change) {
atomic_add_32(&atomic->var, 0 - change);
@ -206,6 +221,11 @@ rx_atomic_dec(rx_atomic_t *atomic) {
(void)__sync_fetch_and_sub(&atomic->var, 1);
}
static_inline int
rx_atomic_dec_and_read(rx_atomic_t *atomic) {
return __sync_sub_and_fetch(&atomic->var, 1);
}
static_inline void
rx_atomic_sub(rx_atomic_t *atomic, int change) {
(void)__sync_fetch_and_sub(&atomic->var, change);
@ -275,6 +295,17 @@ rx_atomic_dec(rx_atomic_t *atomic) {
MUTEX_EXIT(&rx_atomic_mutex);
}
static_inline int
rx_atomic_dec_and_read(rx_atomic_t *atomic) {
int retval;
MUTEX_ENTER(&rx_atomic_mutex);
atomic->var--;
retval = atomic->var;
MUTEX_EXIT(&rx_atomic_mutex);
return retval;
}
static_inline void
rx_atomic_sub(rx_atomic_t *atomic, int change) {
MUTEX_ENTER(&rx_atomic_mutex);