diff options
author | ed <ed@FreeBSD.org> | 2013-04-27 05:01:29 +0000 |
---|---|---|
committer | ed <ed@FreeBSD.org> | 2013-04-27 05:01:29 +0000 |
commit | e8028497402579e4a7f85d8714e9038ace9d44d2 (patch) | |
tree | 33f1253dc7e97a17927f446e96672ec5cef1ea4b /sbin/hastd/refcnt.h | |
parent | f201fcc561ac7eab4ed7997403288e40b18a75a4 (diff) | |
download | FreeBSD-src-e8028497402579e4a7f85d8714e9038ace9d44d2.zip FreeBSD-src-e8028497402579e4a7f85d8714e9038ace9d44d2.tar.gz |
Use C11 <stdatomic.h> instead of our non-standard <machine/atomic.h>.
Reviewed by: pjd
Diffstat (limited to 'sbin/hastd/refcnt.h')
-rw-r--r-- | sbin/hastd/refcnt.h | 19 |
1 files changed, 14 insertions, 5 deletions
diff --git a/sbin/hastd/refcnt.h b/sbin/hastd/refcnt.h index a989df0..5e3fb34 100644 --- a/sbin/hastd/refcnt.h +++ b/sbin/hastd/refcnt.h @@ -32,24 +32,33 @@ #ifndef __REFCNT_H__ #define __REFCNT_H__ -#include <machine/atomic.h> +#include <stdatomic.h> #include "pjdlog.h" +typedef atomic_uint refcnt_t; + +static __inline void +refcnt_init(refcnt_t *count, unsigned int v) +{ + + atomic_init(count, v); +} + static __inline void -refcnt_acquire(volatile unsigned int *count) +refcnt_acquire(refcnt_t *count) { - atomic_add_acq_int(count, 1); + atomic_fetch_add_explicit(count, 1, memory_order_acquire); } static __inline unsigned int -refcnt_release(volatile unsigned int *count) +refcnt_release(refcnt_t *count) { unsigned int old; /* XXX: Should this have a rel membar? */ - old = atomic_fetchadd_int(count, -1); + old = atomic_fetch_sub(count, 1); PJDLOG_ASSERT(old > 0); return (old - 1); } |