1228862Stheraven/*-
2228862Stheraven * Copyright (c) 2011 Ed Schouten <ed@FreeBSD.org>
3228862Stheraven *                    David Chisnall <theraven@FreeBSD.org>
4228862Stheraven * All rights reserved.
5228862Stheraven *
6228862Stheraven * Redistribution and use in source and binary forms, with or without
7228862Stheraven * modification, are permitted provided that the following conditions
8228862Stheraven * are met:
9228862Stheraven * 1. Redistributions of source code must retain the above copyright
10228862Stheraven *    notice, this list of conditions and the following disclaimer.
11228862Stheraven * 2. Redistributions in binary form must reproduce the above copyright
12228862Stheraven *    notice, this list of conditions and the following disclaimer in the
13228862Stheraven *    documentation and/or other materials provided with the distribution.
14228862Stheraven *
15228862Stheraven * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
16228862Stheraven * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
17228862Stheraven * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
18228862Stheraven * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
19228862Stheraven * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
20228862Stheraven * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
21228862Stheraven * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
22228862Stheraven * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
23228862Stheraven * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
24228862Stheraven * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
25228862Stheraven * SUCH DAMAGE.
26228862Stheraven *
27228862Stheraven * $FreeBSD$
28228862Stheraven */
29228862Stheraven
30228862Stheraven#ifndef _STDATOMIC_H_
31228862Stheraven#define	_STDATOMIC_H_
32228862Stheraven
33228862Stheraven#include <sys/cdefs.h>
34228862Stheraven#include <sys/_types.h>
35228862Stheraven
36239960Sed#if __has_extension(c_atomic) || __has_extension(cxx_atomic)
37228862Stheraven#define	__CLANG_ATOMICS
38228977Sed#elif __GNUC_PREREQ__(4, 7)
39228862Stheraven#define	__GNUC_ATOMICS
40251694Sed#elif defined(__GNUC__)
41251694Sed#define	__SYNC_ATOMICS
42251694Sed#else
43228862Stheraven#error "stdatomic.h does not support your compiler"
44228862Stheraven#endif
45228862Stheraven
46228862Stheraven/*
47251347Sed * 7.17.1 Atomic lock-free macros.
48251347Sed */
49251347Sed
50251347Sed#ifdef __GCC_ATOMIC_BOOL_LOCK_FREE
51251347Sed#define	ATOMIC_BOOL_LOCK_FREE		__GCC_ATOMIC_BOOL_LOCK_FREE
52251347Sed#endif
53251347Sed#ifdef __GCC_ATOMIC_CHAR_LOCK_FREE
54251347Sed#define	ATOMIC_CHAR_LOCK_FREE		__GCC_ATOMIC_CHAR_LOCK_FREE
55251347Sed#endif
56251347Sed#ifdef __GCC_ATOMIC_CHAR16_T_LOCK_FREE
57251347Sed#define	ATOMIC_CHAR16_T_LOCK_FREE	__GCC_ATOMIC_CHAR16_T_LOCK_FREE
58251347Sed#endif
59251347Sed#ifdef __GCC_ATOMIC_CHAR32_T_LOCK_FREE
60251347Sed#define	ATOMIC_CHAR32_T_LOCK_FREE	__GCC_ATOMIC_CHAR32_T_LOCK_FREE
61251347Sed#endif
62251347Sed#ifdef __GCC_ATOMIC_WCHAR_T_LOCK_FREE
63251347Sed#define	ATOMIC_WCHAR_T_LOCK_FREE	__GCC_ATOMIC_WCHAR_T_LOCK_FREE
64251347Sed#endif
65251347Sed#ifdef __GCC_ATOMIC_SHORT_LOCK_FREE
66251347Sed#define	ATOMIC_SHORT_LOCK_FREE		__GCC_ATOMIC_SHORT_LOCK_FREE
67251347Sed#endif
68251347Sed#ifdef __GCC_ATOMIC_INT_LOCK_FREE
69251347Sed#define	ATOMIC_INT_LOCK_FREE		__GCC_ATOMIC_INT_LOCK_FREE
70251347Sed#endif
71251347Sed#ifdef __GCC_ATOMIC_LONG_LOCK_FREE
72251347Sed#define	ATOMIC_LONG_LOCK_FREE		__GCC_ATOMIC_LONG_LOCK_FREE
73251347Sed#endif
74251347Sed#ifdef __GCC_ATOMIC_LLONG_LOCK_FREE
75251347Sed#define	ATOMIC_LLONG_LOCK_FREE		__GCC_ATOMIC_LLONG_LOCK_FREE
76251347Sed#endif
77251347Sed#ifdef __GCC_ATOMIC_POINTER_LOCK_FREE
78251347Sed#define	ATOMIC_POINTER_LOCK_FREE	__GCC_ATOMIC_POINTER_LOCK_FREE
79251347Sed#endif
80251347Sed
81251347Sed/*
82228862Stheraven * 7.17.2 Initialization.
83228862Stheraven */
84228862Stheraven
85228862Stheraven#if defined(__CLANG_ATOMICS)
86228882Sed#define	ATOMIC_VAR_INIT(value)		(value)
87234958Stheraven#define	atomic_init(obj, value)		__c11_atomic_init(obj, value)
88228977Sed#else
89228882Sed#define	ATOMIC_VAR_INIT(value)		{ .__val = (value) }
90240970Stijl#define	atomic_init(obj, value)		((void)((obj)->__val = (value)))
91228862Stheraven#endif
92228862Stheraven
93228862Stheraven/*
94228862Stheraven * Clang and recent GCC both provide predefined macros for the memory
95228862Stheraven * orderings.  If we are using a compiler that doesn't define them, use the
96228862Stheraven * clang values - these will be ignored in the fallback path.
97228862Stheraven */
98228862Stheraven
99228862Stheraven#ifndef __ATOMIC_RELAXED
100228882Sed#define __ATOMIC_RELAXED		0
101228862Stheraven#endif
102228862Stheraven#ifndef __ATOMIC_CONSUME
103228882Sed#define __ATOMIC_CONSUME		1
104228862Stheraven#endif
105228862Stheraven#ifndef __ATOMIC_ACQUIRE
106228882Sed#define __ATOMIC_ACQUIRE		2
107228862Stheraven#endif
108228862Stheraven#ifndef __ATOMIC_RELEASE
109228882Sed#define __ATOMIC_RELEASE		3
110228862Stheraven#endif
111228862Stheraven#ifndef __ATOMIC_ACQ_REL
112228882Sed#define __ATOMIC_ACQ_REL		4
113228862Stheraven#endif
114228862Stheraven#ifndef __ATOMIC_SEQ_CST
115228882Sed#define __ATOMIC_SEQ_CST		5
116228862Stheraven#endif
117228862Stheraven
118228862Stheraven/*
119228862Stheraven * 7.17.3 Order and consistency.
120228862Stheraven *
121228862Stheraven * The memory_order_* constants that denote the barrier behaviour of the
122228882Sed * atomic operations.
123228862Stheraven */
124228862Stheraven
125252411Sedtypedef enum {
126228862Stheraven	memory_order_relaxed = __ATOMIC_RELAXED,
127228862Stheraven	memory_order_consume = __ATOMIC_CONSUME,
128228862Stheraven	memory_order_acquire = __ATOMIC_ACQUIRE,
129228862Stheraven	memory_order_release = __ATOMIC_RELEASE,
130228862Stheraven	memory_order_acq_rel = __ATOMIC_ACQ_REL,
131228862Stheraven	memory_order_seq_cst = __ATOMIC_SEQ_CST
132252411Sed} memory_order;
133228862Stheraven
134228862Stheraven/*
135228862Stheraven * 7.17.4 Fences.
136228862Stheraven */
137228862Stheraven
138252411Sedstatic __inline void
139252411Sedatomic_thread_fence(memory_order __order __unused)
140252411Sed{
141252411Sed
142234958Stheraven#ifdef __CLANG_ATOMICS
143252411Sed	__c11_atomic_thread_fence(__order);
144234958Stheraven#elif defined(__GNUC_ATOMICS)
145252411Sed	__atomic_thread_fence(__order);
146228977Sed#else
147252411Sed	__sync_synchronize();
148228862Stheraven#endif
149252411Sed}
150228862Stheraven
151252411Sedstatic __inline void
152252411Sedatomic_signal_fence(memory_order __order __unused)
153252411Sed{
154252411Sed
155252411Sed#ifdef __CLANG_ATOMICS
156252411Sed	__c11_atomic_signal_fence(__order);
157252411Sed#elif defined(__GNUC_ATOMICS)
158252411Sed	__atomic_signal_fence(__order);
159252411Sed#else
160252411Sed	__asm volatile ("" ::: "memory");
161252411Sed#endif
162252411Sed}
163252411Sed
164228862Stheraven/*
165228862Stheraven * 7.17.5 Lock-free property.
166228862Stheraven */
167228862Stheraven
168251694Sed#if defined(_KERNEL)
169251694Sed/* Atomics in kernelspace are always lock-free. */
170228977Sed#define	atomic_is_lock_free(obj) \
171251694Sed	((void)(obj), (_Bool)1)
172251694Sed#elif defined(__CLANG_ATOMICS)
173251694Sed#define	atomic_is_lock_free(obj) \
174251566Sed	__atomic_is_lock_free(sizeof(*(obj)), obj)
175251566Sed#elif defined(__GNUC_ATOMICS)
176251566Sed#define	atomic_is_lock_free(obj) \
177251192Sed	__atomic_is_lock_free(sizeof((obj)->__val), &(obj)->__val)
178228977Sed#else
179228977Sed#define	atomic_is_lock_free(obj) \
180240970Stijl	((void)(obj), sizeof((obj)->__val) <= sizeof(void *))
181228862Stheraven#endif
182228862Stheraven
183228862Stheraven/*
184228862Stheraven * 7.17.6 Atomic integer types.
185228862Stheraven */
186228862Stheraven
187228862Stheraventypedef _Atomic(_Bool)			atomic_bool;
188228862Stheraventypedef _Atomic(char)			atomic_char;
189228862Stheraventypedef _Atomic(signed char)		atomic_schar;
190228862Stheraventypedef _Atomic(unsigned char)		atomic_uchar;
191228862Stheraventypedef _Atomic(short)			atomic_short;
192228862Stheraventypedef _Atomic(unsigned short)		atomic_ushort;
193228862Stheraventypedef _Atomic(int)			atomic_int;
194228862Stheraventypedef _Atomic(unsigned int)		atomic_uint;
195228862Stheraventypedef _Atomic(long)			atomic_long;
196228862Stheraventypedef _Atomic(unsigned long)		atomic_ulong;
197228862Stheraventypedef _Atomic(long long)		atomic_llong;
198228862Stheraventypedef _Atomic(unsigned long long)	atomic_ullong;
199228862Stheraventypedef _Atomic(__char16_t)		atomic_char16_t;
200228862Stheraventypedef _Atomic(__char32_t)		atomic_char32_t;
201264496Stijltypedef _Atomic(___wchar_t)		atomic_wchar_t;
202228862Stheraventypedef _Atomic(__int_least8_t)		atomic_int_least8_t;
203228862Stheraventypedef _Atomic(__uint_least8_t)	atomic_uint_least8_t;
204228862Stheraventypedef _Atomic(__int_least16_t)	atomic_int_least16_t;
205228862Stheraventypedef _Atomic(__uint_least16_t)	atomic_uint_least16_t;
206228862Stheraventypedef _Atomic(__int_least32_t)	atomic_int_least32_t;
207228862Stheraventypedef _Atomic(__uint_least32_t)	atomic_uint_least32_t;
208228862Stheraventypedef _Atomic(__int_least64_t)	atomic_int_least64_t;
209228862Stheraventypedef _Atomic(__uint_least64_t)	atomic_uint_least64_t;
210228862Stheraventypedef _Atomic(__int_fast8_t)		atomic_int_fast8_t;
211228862Stheraventypedef _Atomic(__uint_fast8_t)		atomic_uint_fast8_t;
212228862Stheraventypedef _Atomic(__int_fast16_t)		atomic_int_fast16_t;
213228862Stheraventypedef _Atomic(__uint_fast16_t)	atomic_uint_fast16_t;
214228862Stheraventypedef _Atomic(__int_fast32_t)		atomic_int_fast32_t;
215228862Stheraventypedef _Atomic(__uint_fast32_t)	atomic_uint_fast32_t;
216228862Stheraventypedef _Atomic(__int_fast64_t)		atomic_int_fast64_t;
217228862Stheraventypedef _Atomic(__uint_fast64_t)	atomic_uint_fast64_t;
218228862Stheraventypedef _Atomic(__intptr_t)		atomic_intptr_t;
219228862Stheraventypedef _Atomic(__uintptr_t)		atomic_uintptr_t;
220228862Stheraventypedef _Atomic(__size_t)		atomic_size_t;
221228862Stheraventypedef _Atomic(__ptrdiff_t)		atomic_ptrdiff_t;
222228862Stheraventypedef _Atomic(__intmax_t)		atomic_intmax_t;
223228862Stheraventypedef _Atomic(__uintmax_t)		atomic_uintmax_t;
224228862Stheraven
225228862Stheraven/*
226228862Stheraven * 7.17.7 Operations on atomic types.
227228862Stheraven */
228228862Stheraven
229228862Stheraven/*
230228862Stheraven * Compiler-specific operations.
231228862Stheraven */
232228862Stheraven
233228862Stheraven#if defined(__CLANG_ATOMICS)
234228862Stheraven#define	atomic_compare_exchange_strong_explicit(object, expected,	\
235228862Stheraven    desired, success, failure)						\
236234958Stheraven	__c11_atomic_compare_exchange_strong(object, expected, desired,	\
237228862Stheraven	    success, failure)
238228862Stheraven#define	atomic_compare_exchange_weak_explicit(object, expected,		\
239228862Stheraven    desired, success, failure)						\
240234958Stheraven	__c11_atomic_compare_exchange_weak(object, expected, desired,	\
241228862Stheraven	    success, failure)
242228862Stheraven#define	atomic_exchange_explicit(object, desired, order)		\
243234958Stheraven	__c11_atomic_exchange(object, desired, order)
244228862Stheraven#define	atomic_fetch_add_explicit(object, operand, order)		\
245234958Stheraven	__c11_atomic_fetch_add(object, operand, order)
246228862Stheraven#define	atomic_fetch_and_explicit(object, operand, order)		\
247234958Stheraven	__c11_atomic_fetch_and(object, operand, order)
248228862Stheraven#define	atomic_fetch_or_explicit(object, operand, order)		\
249234958Stheraven	__c11_atomic_fetch_or(object, operand, order)
250228862Stheraven#define	atomic_fetch_sub_explicit(object, operand, order)		\
251234958Stheraven	__c11_atomic_fetch_sub(object, operand, order)
252228862Stheraven#define	atomic_fetch_xor_explicit(object, operand, order)		\
253234958Stheraven	__c11_atomic_fetch_xor(object, operand, order)
254228862Stheraven#define	atomic_load_explicit(object, order)				\
255234958Stheraven	__c11_atomic_load(object, order)
256228862Stheraven#define	atomic_store_explicit(object, desired, order)			\
257234958Stheraven	__c11_atomic_store(object, desired, order)
258228862Stheraven#elif defined(__GNUC_ATOMICS)
259228862Stheraven#define	atomic_compare_exchange_strong_explicit(object, expected,	\
260228977Sed    desired, success, failure)						\
261228977Sed	__atomic_compare_exchange_n(&(object)->__val, expected,		\
262228977Sed	    desired, 0, success, failure)
263228977Sed#define	atomic_compare_exchange_weak_explicit(object, expected,		\
264228977Sed    desired, success, failure)						\
265228977Sed	__atomic_compare_exchange_n(&(object)->__val, expected,		\
266228977Sed	    desired, 1, success, failure)
267228977Sed#define	atomic_exchange_explicit(object, desired, order)		\
268228977Sed	__atomic_exchange_n(&(object)->__val, desired, order)
269228977Sed#define	atomic_fetch_add_explicit(object, operand, order)		\
270228977Sed	__atomic_fetch_add(&(object)->__val, operand, order)
271228977Sed#define	atomic_fetch_and_explicit(object, operand, order)		\
272228977Sed	__atomic_fetch_and(&(object)->__val, operand, order)
273228977Sed#define	atomic_fetch_or_explicit(object, operand, order)		\
274228977Sed	__atomic_fetch_or(&(object)->__val, operand, order)
275228977Sed#define	atomic_fetch_sub_explicit(object, operand, order)		\
276228977Sed	__atomic_fetch_sub(&(object)->__val, operand, order)
277228977Sed#define	atomic_fetch_xor_explicit(object, operand, order)		\
278228977Sed	__atomic_fetch_xor(&(object)->__val, operand, order)
279228977Sed#define	atomic_load_explicit(object, order)				\
280228977Sed	__atomic_load_n(&(object)->__val, order)
281228977Sed#define	atomic_store_explicit(object, desired, order)			\
282228977Sed	__atomic_store_n(&(object)->__val, desired, order)
283228977Sed#else
284252413Sed#define	__atomic_apply_stride(object, operand) \
285252413Sed	(((__typeof__((object)->__val))0) + (operand))
286228977Sed#define	atomic_compare_exchange_strong_explicit(object, expected,	\
287240970Stijl    desired, success, failure)	__extension__ ({			\
288241077Stijl	__typeof__(expected) __ep = (expected);				\
289241077Stijl	__typeof__(*__ep) __e = *__ep;					\
290241077Stijl	(void)(success); (void)(failure);				\
291254497Stijl	(_Bool)((*__ep = __sync_val_compare_and_swap(&(object)->__val,	\
292254497Stijl	    __e, desired)) == __e);					\
293228906Sed})
294228862Stheraven#define	atomic_compare_exchange_weak_explicit(object, expected,		\
295228862Stheraven    desired, success, failure)						\
296228862Stheraven	atomic_compare_exchange_strong_explicit(object, expected,	\
297228862Stheraven		desired, success, failure)
298228862Stheraven#if __has_builtin(__sync_swap)
299228862Stheraven/* Clang provides a full-barrier atomic exchange - use it if available. */
300240970Stijl#define	atomic_exchange_explicit(object, desired, order)		\
301240970Stijl	((void)(order), __sync_swap(&(object)->__val, desired))
302228862Stheraven#else
303228862Stheraven/*
304228862Stheraven * __sync_lock_test_and_set() is only an acquire barrier in theory (although in
305240970Stijl * practice it is usually a full barrier) so we need an explicit barrier before
306228862Stheraven * it.
307228862Stheraven */
308240970Stijl#define	atomic_exchange_explicit(object, desired, order)		\
309240970Stijl__extension__ ({							\
310240970Stijl	__typeof__(object) __o = (object);				\
311240970Stijl	__typeof__(desired) __d = (desired);				\
312240970Stijl	(void)(order);							\
313228862Stheraven	__sync_synchronize();						\
314240970Stijl	__sync_lock_test_and_set(&(__o)->__val, __d);			\
315228862Stheraven})
316228862Stheraven#endif
317228862Stheraven#define	atomic_fetch_add_explicit(object, operand, order)		\
318252413Sed	((void)(order), __sync_fetch_and_add(&(object)->__val,		\
319252413Sed	    __atomic_apply_stride(object, operand)))
320228862Stheraven#define	atomic_fetch_and_explicit(object, operand, order)		\
321241077Stijl	((void)(order), __sync_fetch_and_and(&(object)->__val, operand))
322228862Stheraven#define	atomic_fetch_or_explicit(object, operand, order)		\
323241077Stijl	((void)(order), __sync_fetch_and_or(&(object)->__val, operand))
324228862Stheraven#define	atomic_fetch_sub_explicit(object, operand, order)		\
325252413Sed	((void)(order), __sync_fetch_and_sub(&(object)->__val,		\
326252413Sed	    __atomic_apply_stride(object, operand)))
327228862Stheraven#define	atomic_fetch_xor_explicit(object, operand, order)		\
328241077Stijl	((void)(order), __sync_fetch_and_xor(&(object)->__val, operand))
329228862Stheraven#define	atomic_load_explicit(object, order)				\
330241077Stijl	((void)(order), __sync_fetch_and_add(&(object)->__val, 0))
331241077Stijl#define	atomic_store_explicit(object, desired, order)			\
332241077Stijl	((void)atomic_exchange_explicit(object, desired, order))
333228862Stheraven#endif
334228862Stheraven
335228862Stheraven/*
336228862Stheraven * Convenience functions.
337252411Sed *
338252411Sed * Don't provide these in kernel space. In kernel space, we should be
339252411Sed * disciplined enough to always provide explicit barriers.
340228862Stheraven */
341228862Stheraven
342252411Sed#ifndef _KERNEL
343228862Stheraven#define	atomic_compare_exchange_strong(object, expected, desired)	\
344228862Stheraven	atomic_compare_exchange_strong_explicit(object, expected,	\
345228862Stheraven	    desired, memory_order_seq_cst, memory_order_seq_cst)
346228862Stheraven#define	atomic_compare_exchange_weak(object, expected, desired)		\
347228862Stheraven	atomic_compare_exchange_weak_explicit(object, expected,		\
348228862Stheraven	    desired, memory_order_seq_cst, memory_order_seq_cst)
349228862Stheraven#define	atomic_exchange(object, desired)				\
350228862Stheraven	atomic_exchange_explicit(object, desired, memory_order_seq_cst)
351228862Stheraven#define	atomic_fetch_add(object, operand)				\
352228862Stheraven	atomic_fetch_add_explicit(object, operand, memory_order_seq_cst)
353228862Stheraven#define	atomic_fetch_and(object, operand)				\
354228862Stheraven	atomic_fetch_and_explicit(object, operand, memory_order_seq_cst)
355228862Stheraven#define	atomic_fetch_or(object, operand)				\
356228862Stheraven	atomic_fetch_or_explicit(object, operand, memory_order_seq_cst)
357228862Stheraven#define	atomic_fetch_sub(object, operand)				\
358228862Stheraven	atomic_fetch_sub_explicit(object, operand, memory_order_seq_cst)
359228862Stheraven#define	atomic_fetch_xor(object, operand)				\
360228862Stheraven	atomic_fetch_xor_explicit(object, operand, memory_order_seq_cst)
361228862Stheraven#define	atomic_load(object)						\
362228862Stheraven	atomic_load_explicit(object, memory_order_seq_cst)
363228862Stheraven#define	atomic_store(object, desired)					\
364228862Stheraven	atomic_store_explicit(object, desired, memory_order_seq_cst)
365252411Sed#endif /* !_KERNEL */
366228862Stheraven
367228862Stheraven/*
368228862Stheraven * 7.17.8 Atomic flag type and operations.
369252411Sed *
370252411Sed * XXX: Assume atomic_bool can be used as an atomic_flag. Is there some
371252411Sed * kind of compiler built-in type we could use?
372228862Stheraven */
373228862Stheraven
374252411Sedtypedef struct {
375252411Sed	atomic_bool	__flag;
376252411Sed} atomic_flag;
377228862Stheraven
378252411Sed#define	ATOMIC_FLAG_INIT		{ ATOMIC_VAR_INIT(0) }
379228862Stheraven
380252411Sedstatic __inline _Bool
381252411Sedatomic_flag_test_and_set_explicit(volatile atomic_flag *__object,
382252411Sed    memory_order __order)
383252411Sed{
384254465Semaste	return (atomic_exchange_explicit(&__object->__flag, 1, __order));
385252411Sed}
386228862Stheraven
387252411Sedstatic __inline void
388252411Sedatomic_flag_clear_explicit(volatile atomic_flag *__object, memory_order __order)
389252411Sed{
390252411Sed
391252411Sed	atomic_store_explicit(&__object->__flag, 0, __order);
392252411Sed}
393252411Sed
394252411Sed#ifndef _KERNEL
395252411Sedstatic __inline _Bool
396252411Sedatomic_flag_test_and_set(volatile atomic_flag *__object)
397252411Sed{
398252411Sed
399252411Sed	return (atomic_flag_test_and_set_explicit(__object,
400252411Sed	    memory_order_seq_cst));
401252411Sed}
402252411Sed
403252411Sedstatic __inline void
404252411Sedatomic_flag_clear(volatile atomic_flag *__object)
405252411Sed{
406252411Sed
407252411Sed	atomic_flag_clear_explicit(__object, memory_order_seq_cst);
408252411Sed}
409252411Sed#endif /* !_KERNEL */
410252411Sed
411228862Stheraven#endif /* !_STDATOMIC_H_ */
412