ARGOBOTS  9f08f49cbe21d7526438dbc6711ec10d9bd0717b
abtd_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 ABTD_SPINLOCK_H_INCLUDED
7 #define ABTD_SPINLOCK_H_INCLUDED
8 
9 typedef struct ABTD_spinlock {
12 
13 #define ABTD_SPINLOCK_STATIC_INITIALIZER() \
14  { \
15  ABTD_ATOMIC_BOOL_STATIC_INITIALIZER(0) \
16  }
17 
18 static inline ABT_bool ABTD_spinlock_is_locked(const ABTD_spinlock *p_lock)
19 {
20  return ABTD_atomic_acquire_load_bool(&p_lock->val);
21 }
22 
23 static inline void ABTD_spinlock_clear(ABTD_spinlock *p_lock)
24 {
26 }
27 
28 static inline void ABTD_spinlock_acquire(ABTD_spinlock *p_lock)
29 {
30  while (ABTD_atomic_test_and_set_bool(&p_lock->val)) {
31  while (ABTD_spinlock_is_locked(p_lock) != ABT_FALSE)
32  ;
33  }
34 }
35 
36 /* Return ABT_FALSE if the lock is acquired. */
38 {
40 }
41 
42 static inline void ABTD_spinlock_release(ABTD_spinlock *p_lock)
43 {
45 }
46 
47 #endif /* ABTD_SPINLOCK_H_INCLUDED */
ABT_bool
int ABT_bool
Boolean type.
Definition: abt.h:1001
ABTD_spinlock::val
ABTD_atomic_bool val
Definition: abtd_spinlock.h:10
ABTD_atomic_test_and_set_bool
static uint16_t ABTD_atomic_test_and_set_bool(ABTD_atomic_bool *ptr)
Definition: abtd_atomic.h:719
ABTD_spinlock
Definition: abtd_spinlock.h:9
ABTD_spinlock_acquire
static void ABTD_spinlock_acquire(ABTD_spinlock *p_lock)
Definition: abtd_spinlock.h:28
ABTD_spinlock
struct ABTD_spinlock ABTD_spinlock
ABTD_spinlock_try_acquire
static ABT_bool ABTD_spinlock_try_acquire(ABTD_spinlock *p_lock)
Definition: abtd_spinlock.h:37
ABTD_atomic_relaxed_clear_bool
static void ABTD_atomic_relaxed_clear_bool(ABTD_atomic_bool *ptr)
Definition: abtd_atomic.h:729
ABT_TRUE
#define ABT_TRUE
True constant for ABT_bool.
Definition: abt.h:748
ABTD_spinlock_clear
static void ABTD_spinlock_clear(ABTD_spinlock *p_lock)
Definition: abtd_spinlock.h:23
ABT_FALSE
#define ABT_FALSE
False constant for ABT_bool.
Definition: abt.h:750
ABTD_atomic_acquire_load_bool
static ABT_bool ABTD_atomic_acquire_load_bool(const ABTD_atomic_bool *ptr)
Definition: abtd_atomic.h:861
ABTD_spinlock_release
static void ABTD_spinlock_release(ABTD_spinlock *p_lock)
Definition: abtd_spinlock.h:42
ABTD_atomic_release_clear_bool
static void ABTD_atomic_release_clear_bool(ABTD_atomic_bool *ptr)
Definition: abtd_atomic.h:738
ABTD_atomic_bool
Definition: abtd_atomic.h:11
ABTD_spinlock_is_locked
static ABT_bool ABTD_spinlock_is_locked(const ABTD_spinlock *p_lock)
Definition: abtd_spinlock.h:18