ARGOBOTS  66b1c39742507d8df30e8d28c54839b961a14814
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Groups
abti_spinlock.h
Go to the documentation of this file.
1 /* -*- Mode: C; c-basic-offset:4 ; indent-tabs-mode:nil ; -*- */
2 /*
3  * See COPYRIGHT in top-level directory.
4  */
5 
6 #ifndef ABTI_SPINLOCK_H_INCLUDED
7 #define ABTI_SPINLOCK_H_INCLUDED
8 
9 struct ABTI_spinlock {
10  ABTD_atomic_bool val;
11 };
12 
13 #define ABTI_SPINLOCK_STATIC_INITIALIZER() \
14  { \
15  ABTD_ATOMIC_BOOL_STATIC_INITIALIZER(0) \
16  }
17 
18 static inline void ABTI_spinlock_clear(ABTI_spinlock *p_lock)
19 {
20  ABTD_atomic_relaxed_clear_bool(&p_lock->val);
21 }
22 
23 static inline void ABTI_spinlock_acquire(ABTI_spinlock *p_lock)
24 {
25  while (ABTD_atomic_test_and_set_bool(&p_lock->val)) {
26  while (ABTD_atomic_acquire_load_bool(&p_lock->val) != ABT_FALSE)
27  ;
28  }
29 }
30 
31 static inline void ABTI_spinlock_release(ABTI_spinlock *p_lock)
32 {
33  ABTD_atomic_release_clear_bool(&p_lock->val);
34 }
35 
36 #endif /* ABTI_SPINLOCK_H_INCLUDED */
#define ABT_FALSE
Definition: abt.h:285