Changing refcount(9) to use a refcount_t

John Baldwin jhb at freebsd.org
Fri Dec 23 13:34:10 UTC 2011


On Thursday, December 22, 2011 4:47:28 pm Ed Schouten wrote:
> Hi all,
> 
> As some of you may know, the upcoming C standard has support for atomic
> operations. Looking at how they implemented it, it seems that they tried
> to keep it somehow compatible with existing compiler standards. For
> example, one could implement a poor-man's version of it as follows:
> 
> | #define _Atomic(T) struct { pthread_mutex_t m; T v; }
> |
> | #define ATOMIC_VAR_INIT(value) { PTHREAD_MUTEX_INITIALIZER, (value) }
> | 
> | #define atomic_store(object, value) do {
> | 	pthread_mutex_lock(&(object)->m);
> | 	(object)->v = (value);
> | 	pthread_mutex_unlock(&(object)->m);
> | } while(0)
> |
> | ...
> 
> Voila; atomics!
> 
> Just out of curiosity, I did some experiments with this, where I have a
> <stdatomic.h> that works with both Clang and GCC (except ARM and MIPS,
> for some reason). My first test subject: <sys/refcount.h>.

Hmm, are we really aiming to replace <machine/atomic.h> with the C1X API
instead?

FWIW, I thought about making a refcount_t when first writing <sys/refcount.h> 
but bde@ talked me out of it.  Bruce is of the general opinion that we should
avoid adding new *_t typedefs when we can help it.

-- 
John Baldwin


More information about the freebsd-fs mailing list