11 #if defined(HAVE_CLOCK_GETTIME) 13 clock_gettime(CLOCK_REALTIME, &ts);
14 return ((
double)ts.tv_sec) + 1.0e-9 * ((double)ts.tv_nsec);
15 #elif defined(HAVE_GETTIMEOFDAY) 17 gettimeofday(&tv, NULL);
18 return ((
double)tv.tv_sec) + 1.0e-6 * ((double)tv.tv_usec);
20 #error "No timer function available" 118 ABTI_pool *p_pool = ABTI_pool_get_ptr(pool);
123 access = p_pool->access;
127 ABTI_spinlock_clear(&p_data->mutex);
130 p_data->num_units = 0;
131 p_data->p_head = NULL;
132 p_data->p_tail = NULL;
134 p_pool->data = p_data;
142 ABTI_pool *p_pool = ABTI_pool_get_ptr(pool);
152 ABTI_pool *p_pool = ABTI_pool_get_ptr(pool);
154 return p_data->num_units;
159 ABTI_pool *p_pool = ABTI_pool_get_ptr(pool);
163 ABTI_spinlock_acquire(&p_data->mutex);
164 if (p_data->num_units == 0) {
165 p_unit->p_prev = p_unit;
166 p_unit->p_next = p_unit;
167 p_data->p_head = p_unit;
168 p_data->p_tail = p_unit;
170 unit_t *p_head = p_data->p_head;
171 unit_t *p_tail = p_data->p_tail;
172 p_tail->p_next = p_unit;
173 p_head->p_prev = p_unit;
174 p_unit->p_prev = p_tail;
175 p_unit->p_next = p_head;
176 p_data->p_tail = p_unit;
180 ABTD_atomic_release_store_int(&p_unit->is_in_pool, 1);
181 ABTI_spinlock_release(&p_data->mutex);
186 ABTI_pool *p_pool = ABTI_pool_get_ptr(pool);
190 if (p_data->num_units == 0) {
191 p_unit->p_prev = p_unit;
192 p_unit->p_next = p_unit;
193 p_data->p_head = p_unit;
194 p_data->p_tail = p_unit;
196 unit_t *p_head = p_data->p_head;
197 unit_t *p_tail = p_data->p_tail;
198 p_tail->p_next = p_unit;
199 p_head->p_prev = p_unit;
200 p_unit->p_prev = p_tail;
201 p_unit->p_next = p_head;
202 p_data->p_tail = p_unit;
206 ABTD_atomic_release_store_int(&p_unit->is_in_pool, 1);
211 ABTI_pool *p_pool = ABTI_pool_get_ptr(pool);
219 ABTI_spinlock_acquire(&p_data->mutex);
220 if (p_data->num_units > 0) {
221 p_unit = p_data->p_head;
222 if (p_data->num_units == 1) {
223 p_data->p_head = NULL;
224 p_data->p_tail = NULL;
226 p_unit->p_prev->p_next = p_unit->p_next;
227 p_unit->p_next->p_prev = p_unit->p_prev;
228 p_data->p_head = p_unit->p_next;
232 p_unit->p_prev = NULL;
233 p_unit->p_next = NULL;
234 ABTD_atomic_release_store_int(&p_unit->is_in_pool, 0);
237 ABTI_spinlock_release(&p_data->mutex);
239 ABTI_spinlock_release(&p_data->mutex);
241 const int sleep_nsecs = 100;
242 struct timespec ts = { 0, sleep_nsecs };
243 nanosleep(&ts, NULL);
246 if (elapsed > abstime_secs)
256 ABTI_pool *p_pool = ABTI_pool_get_ptr(pool);
261 ABTI_spinlock_acquire(&p_data->mutex);
262 if (p_data->num_units > 0) {
263 p_unit = p_data->p_head;
264 if (p_data->num_units == 1) {
265 p_data->p_head = NULL;
266 p_data->p_tail = NULL;
268 p_unit->p_prev->p_next = p_unit->p_next;
269 p_unit->p_next->p_prev = p_unit->p_prev;
270 p_data->p_head = p_unit->p_next;
274 p_unit->p_prev = NULL;
275 p_unit->p_next = NULL;
276 ABTD_atomic_release_store_int(&p_unit->is_in_pool, 0);
280 ABTI_spinlock_release(&p_data->mutex);
287 ABTI_pool *p_pool = ABTI_pool_get_ptr(pool);
292 if (p_data->num_units > 0) {
293 p_unit = p_data->p_head;
294 if (p_data->num_units == 1) {
295 p_data->p_head = NULL;
296 p_data->p_tail = NULL;
298 p_unit->p_prev->p_next = p_unit->p_next;
299 p_unit->p_next->p_prev = p_unit->p_prev;
300 p_data->p_head = p_unit->p_next;
304 p_unit->p_prev = NULL;
305 p_unit->p_next = NULL;
306 ABTD_atomic_release_store_int(&p_unit->is_in_pool, 0);
316 ABTI_pool *p_pool = ABTI_pool_get_ptr(pool);
320 ABTI_CHECK_TRUE_RET(p_data->num_units != 0,
ABT_ERR_POOL);
321 ABTI_CHECK_TRUE_RET(ABTD_atomic_acquire_load_int(&p_unit->is_in_pool) == 1,
324 ABTI_spinlock_acquire(&p_data->mutex);
325 if (p_data->num_units == 1) {
326 p_data->p_head = NULL;
327 p_data->p_tail = NULL;
329 p_unit->p_prev->p_next = p_unit->p_next;
330 p_unit->p_next->p_prev = p_unit->p_prev;
331 if (p_unit == p_data->p_head) {
332 p_data->p_head = p_unit->p_next;
333 }
else if (p_unit == p_data->p_tail) {
334 p_data->p_tail = p_unit->p_prev;
339 ABTD_atomic_release_store_int(&p_unit->is_in_pool, 0);
340 ABTI_spinlock_release(&p_data->mutex);
342 p_unit->p_prev = NULL;
343 p_unit->p_next = NULL;
350 ABTI_pool *p_pool = ABTI_pool_get_ptr(pool);
354 ABTI_CHECK_TRUE_RET(p_data->num_units != 0,
ABT_ERR_POOL);
355 ABTI_CHECK_TRUE_RET(ABTD_atomic_acquire_load_int(&p_unit->is_in_pool) == 1,
358 if (p_data->num_units == 1) {
359 p_data->p_head = NULL;
360 p_data->p_tail = NULL;
362 p_unit->p_prev->p_next = p_unit->p_next;
363 p_unit->p_next->p_prev = p_unit->p_prev;
364 if (p_unit == p_data->p_head) {
365 p_data->p_head = p_unit->p_next;
366 }
else if (p_unit == p_data->p_tail) {
367 p_data->p_tail = p_unit->p_prev;
372 ABTD_atomic_release_store_int(&p_unit->is_in_pool, 0);
373 p_unit->p_prev = NULL;
374 p_unit->p_next = NULL;
383 ABTI_pool *p_pool = ABTI_pool_get_ptr(pool);
386 access = p_pool->access;
388 ABTI_spinlock_acquire(&p_data->mutex);
391 size_t num_units = p_data->num_units;
392 unit_t *p_unit = p_data->p_head;
393 while (num_units--) {
397 p_unit = p_unit->p_next;
401 ABTI_spinlock_release(&p_data->mutex);
420 h_thread = p_unit->handle.thread;
432 h_task = p_unit->handle.task;
442 return ABTD_atomic_acquire_load_int(&p_unit->is_in_pool) ?
ABT_TRUE 448 ABTI_thread *p_thread = ABTI_thread_get_ptr(thread);
449 unit_t *p_unit = &p_thread->unit_def;
450 p_unit->p_prev = NULL;
451 p_unit->p_next = NULL;
452 ABTD_atomic_relaxed_store_int(&p_unit->is_in_pool, 0);
453 p_unit->handle.thread = thread;
461 ABTI_task *p_task = ABTI_task_get_ptr(task);
462 unit_t *p_unit = &p_task->unit_def;
463 p_unit->p_prev = NULL;
464 p_unit->p_next = NULL;
465 ABTD_atomic_relaxed_store_int(&p_unit->is_in_pool, 0);
466 p_unit->handle.task = task;
static int pool_remove_private(ABT_pool pool, ABT_unit unit)
static ABT_thread unit_get_thread(ABT_unit unit)
struct ABT_unit_opaque * ABT_unit
static ABT_unit pool_pop_shared(ABT_pool pool)
ABT_unit_get_task_fn u_get_task
#define ABT_ERR_INV_POOL_ACCESS
static void pool_push_shared(ABT_pool pool, ABT_unit unit)
struct ABT_task_opaque * ABT_task
static void * ABTU_malloc(size_t size)
static size_t pool_get_size(ABT_pool pool)
ABT_unit_get_thread_fn u_get_thread
static ABT_bool unit_is_in_pool(ABT_unit unit)
struct ABT_pool_opaque * ABT_pool
ABT_unit_is_in_pool_fn u_is_in_pool
struct ABT_thread_opaque * ABT_thread
static ABT_unit unit_create_from_thread(ABT_thread thread)
#define HANDLE_ERROR_FUNC_WITH_CODE(n)
static void pool_push_private(ABT_pool pool, ABT_unit unit)
static int pool_free(ABT_pool pool)
static ABT_unit unit_create_from_task(ABT_task task)
static ABT_unit pool_pop_private(ABT_pool pool)
ABT_unit_create_from_task_fn u_create_from_task
static int pool_remove_shared(ABT_pool pool, ABT_unit unit)
static void unit_free(ABT_unit *unit)
ABT_unit_create_from_thread_fn u_create_from_thread
static double get_cur_time(void)
static ABT_unit_type unit_get_type(ABT_unit unit)
static ABT_task unit_get_task(ABT_unit unit)
struct ABT_pool_config_opaque * ABT_pool_config
ABT_unit_get_type_fn u_get_type
ABT_pool_get_size_fn p_get_size
static int pool_print_all(ABT_pool pool, void *arg, void(*print_fn)(void *, ABT_unit))
static int pool_init(ABT_pool pool, ABT_pool_config config)
static void ABTU_free(void *ptr)
ABT_pool_remove_fn p_remove
ABT_pool_print_all_fn p_print_all
static ABT_unit pool_pop_timedwait(ABT_pool pool, double abstime_secs)
ABT_pool_pop_timedwait_fn p_pop_timedwait
static data_t * pool_get_data_ptr(void *p_data)