ARGOBOTS  1.1
abtd_futex.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_FUTEX_H_INCLUDED
7 #define ABTD_FUTEX_H_INCLUDED
8 
9 #ifndef ABT_CONFIG_ACTIVE_WAIT_POLICY
10 
11 /* ABTD_futex_multiple supports a wait-broadcast pattern. ABTD_futex_multiple
12  * allows multiple waiters. */
14 
15 /* Initialize ABTD_futex_multiple. */
16 static inline void ABTD_futex_multiple_init(ABTD_futex_multiple *p_futex);
17 
18 /* This routine unlocks p_lock and makes the underlying Pthread block on
19  * p_futex. Broadcast can wake up this waiter. Spurious wakeup does not
20  * happen. */
22  ABTD_spinlock *p_lock);
23 
24 /* This routine unlocks p_lock and makes the underlying Pthread block on
25  * p_futex. Broadcast can wake up this waiter. By nature, spurious wakeup
26  * might happen, so the caller needs to check the current time if necessary. */
28  ABTD_spinlock *p_lock,
29  double wait_time_sec);
30 
31 /* This routine wakes up waiters that are waiting on p_futex. This function
32  * must be called when a lock (p_lock above) is taken. */
34 
35 /* ABTD_futex_single supports a suspend-resume pattern. ABTD_futex_single
36  * allows only a single waiter. */
38 
39 /* Initialize ABTD_futex_single. */
40 static inline void ABTD_futex_single_init(ABTD_futex_single *p_futex);
41 
42 /* This routine suspends the underlying Pthread. Only one thread can suspend
43  * on a single p_futex. This suspended thread must be woken up by
44  * ABTD_futex_resume(). Spurious wakeup does not happen.
45  *
46  * p_futex must be new; it may not have been used after initialization. */
48 
49 /* This routine wakes up a Pthread suspended by ABTD_futex_suspend(). This
50  * routine blocks if no Pthread is waiting on p_futex. */
52 
53 #ifdef ABT_CONFIG_USE_LINUX_FUTEX
54 
55 struct ABTD_futex_multiple {
56  ABTD_atomic_int val;
57 };
58 
59 static inline void ABTD_futex_multiple_init(ABTD_futex_multiple *p_futex)
60 {
61  ABTD_atomic_relaxed_store_int(&p_futex->val, 0);
62 }
63 
64 struct ABTD_futex_single {
65  ABTD_atomic_int val;
66 };
67 
68 static inline void ABTD_futex_single_init(ABTD_futex_single *p_futex)
69 {
70  ABTD_atomic_relaxed_store_int(&p_futex->val, 0);
71 }
72 
73 #else /* ABT_CONFIG_USE_LINUX_FUTEX */
74 
76  void *p_next; /* pthread_sync */
77 };
78 
79 static inline void ABTD_futex_multiple_init(ABTD_futex_multiple *p_futex)
80 {
81  p_futex->p_next = NULL;
82 }
83 
86 };
87 
88 static inline void ABTD_futex_single_init(ABTD_futex_single *p_futex)
89 {
91 }
92 
93 #endif /* !ABT_CONFIG_USE_LINUX_FUTEX */
94 
95 #endif /* !ABT_CONFIG_ACTIVE_WAIT_POLICY */
96 
97 #endif /* ABTD_FUTEX_H_INCLUDED */
ABTD_futex_single_init
static void ABTD_futex_single_init(ABTD_futex_single *p_futex)
Definition: abtd_futex.h:88
ABTD_futex_suspend
void ABTD_futex_suspend(ABTD_futex_single *p_futex)
Definition: abtd_futex.c:191
ABTD_atomic_int
Definition: abtd_atomic.h:15
ABTD_futex_multiple_init
static void ABTD_futex_multiple_init(ABTD_futex_multiple *p_futex)
Definition: abtd_futex.h:79
ABTD_spinlock
Definition: abtd_spinlock.h:9
ABTD_atomic_ptr
Definition: abtd_atomic.h:39
ABTD_atomic_relaxed_store_int
static void ABTD_atomic_relaxed_store_int(ABTD_atomic_int *ptr, int val)
Definition: abtd_atomic.h:996
ABTD_futex_multiple
Definition: abtd_futex.h:75
ABTD_futex_single
Definition: abtd_futex.h:84
ABTD_futex_wait_and_unlock
void ABTD_futex_wait_and_unlock(ABTD_futex_multiple *p_futex, ABTD_spinlock *p_lock)
Definition: abtd_futex.c:87
ABTD_futex_resume
void ABTD_futex_resume(ABTD_futex_single *p_futex)
Definition: abtd_futex.c:216
ABTD_futex_single::p_sync_obj
ABTD_atomic_ptr p_sync_obj
Definition: abtd_futex.h:85
ABTD_futex_timedwait_and_unlock
void ABTD_futex_timedwait_and_unlock(ABTD_futex_multiple *p_futex, ABTD_spinlock *p_lock, double wait_time_sec)
Definition: abtd_futex.c:117
ABTD_futex_multiple::p_next
void * p_next
Definition: abtd_futex.h:76
ABTD_futex_broadcast
void ABTD_futex_broadcast(ABTD_futex_multiple *p_futex)
Definition: abtd_futex.c:174
ABTD_atomic_relaxed_store_ptr
static void ABTD_atomic_relaxed_store_ptr(ABTD_atomic_ptr *ptr, void *val)
Definition: abtd_atomic.h:1055