review stdatomic.h fixes

Tijl Coosemans tijl at coosemans.org
Tue Sep 11 14:12:09 UTC 2012


On 11-09-2012 15:43, Konstantin Belousov wrote:
> On Mon, Sep 10, 2012 at 08:41:55PM +0200, Tijl Coosemans wrote:
>> Hi,
>>
>> Below is a patch+descriptions for stdatomic.h that I was hoping somebody could
>> review.
>>
>>> Index: stdatomic.h
>>> ===================================================================
>>> --- stdatomic.h	(revision 240316)
>>> +++ stdatomic.h	(working copy)
>>> @@ -54,9 +54,7 @@
>>>  #define	atomic_init(obj, value)		__c11_atomic_init(obj, value)
>>>  #else
>>>  #define	ATOMIC_VAR_INIT(value)		{ .__val = (value) }
>>> -#define	atomic_init(obj, value) do {					\
>>> -	(obj)->__val = (value);						\
>>> -} while (0)
>>> +#define	atomic_init(obj, value)		((void)((obj)->__val = (value)))
>>
>> atomic_init() is defined as a (generic) function returning void, so make this
>> a void expression instead of using do-while.
> Why not define it as static inline function for real ? For some symbols,
> e.g.atomic_is_lock_free(), you would need both function and macro, as it
> is done for gcc case.

It's not an ordinary function but a generic function. The arguments can have
different types. The standard defines it as

void atomic_init( volatile A *obj, C value );

Where A can be any atomic type and C the corresponding non-atomic type.

-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 228 bytes
Desc: OpenPGP digital signature
Url : http://lists.freebsd.org/pipermail/freebsd-threads/attachments/20120911/8b6c37b9/signature.pgp


More information about the freebsd-threads mailing list