8 #ifndef ABT_CONFIG_ACTIVE_WAIT_POLICY
10 #ifdef ABT_CONFIG_USE_LINUX_FUTEX
14 #include <linux/futex.h>
23 syscall(SYS_futex, &p_futex->val.val, FUTEX_WAIT_PRIVATE, original_val,
34 struct timespec wait_time;
35 wait_time.tv_sec = (time_t)wait_time_sec;
37 (long)((wait_time_sec - (
double)(time_t)wait_time_sec) * 1.0e9);
38 syscall(SYS_futex, &p_futex->val.val, FUTEX_WAIT_PRIVATE, original_val,
46 syscall(SYS_futex, &p_futex->val.val, FUTEX_WAKE_PRIVATE, INT_MAX, NULL,
54 syscall(SYS_futex, &p_futex->val.val, FUTEX_WAIT_PRIVATE, 0, NULL, NULL,
65 syscall(SYS_futex, &p_futex->val.val, FUTEX_WAKE_PRIVATE, 1, NULL, NULL, 0);
81 #define PTHREAD_SYNC_STATIC_INITIALIZER \
83 PTHREAD_MUTEX_INITIALIZER, PTHREAD_COND_INITIALIZER, NULL, NULL, \
84 ABTD_ATOMIC_INT_STATIC_INITIALIZER(0), \
91 pthread_mutex_lock(&sync_obj.
mutex);
98 p_futex->
p_next = (
void *)&sync_obj;
101 pthread_cond_wait(&sync_obj.
cond, &sync_obj.
mutex);
105 pthread_mutex_unlock(&sync_obj.
mutex);
113 pthread_cond_destroy(&sync_obj.
cond);
114 pthread_mutex_destroy(&sync_obj.
mutex);
119 double wait_time_sec)
123 struct timespec wait_time;
124 clock_gettime(CLOCK_REALTIME, &wait_time);
125 wait_time.tv_sec += (time_t)wait_time_sec;
127 (long)((wait_time_sec - (
double)(time_t)wait_time_sec) * 1.0e9);
128 if (wait_time.tv_nsec >= 1e9) {
129 wait_time.tv_sec += 1;
130 wait_time.tv_nsec -= 1e9;
132 pthread_mutex_lock(&sync_obj.
mutex);
137 p_next->
p_prev = &sync_obj;
139 p_futex->
p_next = (
void *)&sync_obj;
141 pthread_cond_timedwait(&sync_obj.
cond, &sync_obj.
mutex, &wait_time);
145 pthread_mutex_unlock(&sync_obj.
mutex);
159 if (p_futex->
p_next == (
void *)&sync_obj) {
160 p_futex->
p_next = (
void *)sync_obj.p_next;
163 sync_obj.p_prev->p_next = sync_obj.p_next;
164 sync_obj.p_next->p_prev = sync_obj.p_prev;
170 pthread_cond_destroy(&sync_obj.
cond);
171 pthread_mutex_destroy(&sync_obj.
mutex);
180 pthread_mutex_lock(&p_cur->
mutex);
182 pthread_cond_broadcast(&p_cur->
cond);
183 pthread_mutex_unlock(&p_cur->
mutex);
198 pthread_mutex_lock(&sync_obj.
mutex);
202 (
void *)&sync_obj)) {
206 pthread_cond_wait(&sync_obj.cond, &sync_obj.mutex);
210 pthread_mutex_unlock(&sync_obj.mutex);
212 pthread_cond_destroy(&sync_obj.cond);
213 pthread_mutex_destroy(&sync_obj.mutex);
222 void *invalid_ptr = (
void *)((intptr_t)1);
225 if (ret_val == NULL) {
233 pthread_mutex_lock(&p_sync_obj->
mutex);
237 pthread_cond_signal(&p_sync_obj->
cond);
238 pthread_mutex_unlock(&p_sync_obj->
mutex);