ARGOBOTS  0fe9a69fef0da01b7d13b05bf3ea11c116497027
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 {
11 };
12 
13 #define ABTI_SPINLOCK_STATIC_INITIALIZER() \
14  { \
15  ABTD_ATOMIC_BOOL_STATIC_INITIALIZER(0) \
16  }
17 
18 static inline ABT_bool ABTI_spinlock_is_locked(const ABTI_spinlock *p_lock)
19 {
20  return ABTD_atomic_acquire_load_bool(&p_lock->val);
21 }
22 
23 static inline void ABTI_spinlock_clear(ABTI_spinlock *p_lock)
24 {
26 }
27 
28 static inline void ABTI_spinlock_acquire(ABTI_spinlock *p_lock)
29 {
30  while (ABTD_atomic_test_and_set_bool(&p_lock->val)) {
31  while (ABTI_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 ABTI_spinlock_release(ABTI_spinlock *p_lock)
43 {
45 }
46 
47 #endif /* ABTI_SPINLOCK_H_INCLUDED */
ABT_bool
int ABT_bool
Boolean type.
Definition: abt.h:999
ABTI_spinlock_clear
static void ABTI_spinlock_clear(ABTI_spinlock *p_lock)
Definition: abti_spinlock.h:23
ABTI_spinlock_is_locked
static ABT_bool ABTI_spinlock_is_locked(const ABTI_spinlock *p_lock)
Definition: abti_spinlock.h:18
ABTD_atomic_test_and_set_bool
static uint16_t ABTD_atomic_test_and_set_bool(ABTD_atomic_bool *ptr)
Definition: abtd_atomic.h:719
ABTI_spinlock_try_acquire
static ABT_bool ABTI_spinlock_try_acquire(ABTI_spinlock *p_lock)
Definition: abti_spinlock.h:37
ABTI_spinlock
Definition: abti_spinlock.h:9
ABTI_spinlock_release
static void ABTI_spinlock_release(ABTI_spinlock *p_lock)
Definition: abti_spinlock.h:42
ABTI_spinlock_acquire
static void ABTI_spinlock_acquire(ABTI_spinlock *p_lock)
Definition: abti_spinlock.h:28
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:746
ABT_FALSE
#define ABT_FALSE
False constant for ABT_bool.
Definition: abt.h:748
ABTD_atomic_acquire_load_bool
static ABT_bool ABTD_atomic_acquire_load_bool(const ABTD_atomic_bool *ptr)
Definition: abtd_atomic.h:861
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
ABTI_spinlock::val
ABTD_atomic_bool val
Definition: abti_spinlock.h:10