P99
p99_atomic_flag.h
Go to the documentation of this file.
1 /* This may look like nonsense, but it really is -*- mode: C; coding: utf-8 -*- */
2 /* */
3 /* Except for parts copied from previous work and as explicitly stated below, */
4 /* the author and copyright holder for this work is */
5 /* (C) copyright 2013 Jens Gustedt, INRIA, France */
6 /* */
7 /* This file is free software; it is part of the P99 project. */
8 /* */
9 /* Licensed under the Apache License, Version 2.0 (the "License"); */
10 /* you may not use this file except in compliance with the License. */
11 /* You may obtain a copy of the License at */
12 /* */
13 /* http://www.apache.org/licenses/LICENSE-2.0 */
14 /* */
15 /* Unless required by applicable law or agreed to in writing, software */
16 /* distributed under the License is distributed on an "AS IS" BASIS, */
17 /* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. */
18 /* See the License for the specific language governing permissions and */
19 /* limitations under the License. */
20 /* */
21 #ifndef P99_ATOMIC_FLAG_H_
22 #define P99_ATOMIC_FLAG_H_ 1
23 
35 void atomic_flag_lock(volatile atomic_flag *p00_objp) {
36  while (atomic_flag_test_and_set_explicit(p00_objp, memory_order_acquire));
37 }
38 
51 _Bool atomic_flag_trylock(volatile atomic_flag *p00_objp) {
52  return !atomic_flag_test_and_set_explicit(p00_objp, memory_order_acquire);
53 }
54 
63 void atomic_flag_unlock(volatile atomic_flag *p00_objp) {
64  atomic_flag_clear_explicit(p00_objp, memory_order_release);
65 }
66 
90 #define P99_SPIN_EXCLUDE(FLAGP) P00_SPIN_EXCLUDE(FLAGP, P99_UNIQ(flg))
91 
92 #define P00_SPIN_EXCLUDE(FLAGP, ID) \
93 P00_BLK_START \
94 P00_BLK_DECL(register atomic_flag volatile*const, ID, (FLAGP)) \
95 P00_BLK_BEFAFT(atomic_flag_lock(ID), \
96  atomic_flag_unlock(ID)) \
97 P00_BLK_END
98 
99 #endif
p99_inline
#define p99_inline
Try to force a function always to be inlined.
Definition: p99_compiler.h:496