30 pthread_mutex_t mutex;
71 ABTI_pool *p_pool = ABTI_pool_get_ptr(pool);
75 pthread_mutex_init(&p_data->mutex, NULL);
76 pthread_cond_init(&p_data->cond, NULL);
78 p_data->num_units = 0;
79 p_data->p_head = NULL;
80 p_data->p_tail = NULL;
82 p_pool->data = p_data;
90 ABTI_pool *p_pool = ABTI_pool_get_ptr(pool);
93 pthread_mutex_destroy(&p_data->mutex);
94 pthread_cond_destroy(&p_data->cond);
102 ABTI_pool *p_pool = ABTI_pool_get_ptr(pool);
104 return p_data->num_units;
109 ABTI_pool *p_pool = ABTI_pool_get_ptr(pool);
111 unit_t *p_unit = (unit_t *)unit;
113 pthread_mutex_lock(&p_data->mutex);
114 if (p_data->num_units == 0) {
115 p_unit->p_prev = p_unit;
116 p_unit->p_next = p_unit;
117 p_data->p_head = p_unit;
118 p_data->p_tail = p_unit;
120 unit_t *p_head = p_data->p_head;
121 unit_t *p_tail = p_data->p_tail;
122 p_tail->p_next = p_unit;
123 p_head->p_prev = p_unit;
124 p_unit->p_prev = p_tail;
125 p_unit->p_next = p_head;
126 p_data->p_tail = p_unit;
130 ABTD_atomic_release_store_int(&p_unit->is_in_pool, 1);
131 pthread_cond_signal(&p_data->cond);
132 pthread_mutex_unlock(&p_data->mutex);
138 ts_out->tv_sec = (time_t)seconds;
139 ts_out->tv_nsec = (long)((seconds - ts_out->tv_sec) * 1000000000.0);
144 ABTI_pool *p_pool = ABTI_pool_get_ptr(pool);
146 unit_t *p_unit = NULL;
149 pthread_mutex_lock(&p_data->mutex);
151 if (!p_data->num_units) {
154 pthread_cond_timedwait(&p_data->cond, &p_data->mutex, &ts);
157 if (p_data->num_units > 0) {
158 p_unit = p_data->p_head;
159 if (p_data->num_units == 1) {
160 p_data->p_head = NULL;
161 p_data->p_tail = NULL;
163 p_unit->p_prev->p_next = p_unit->p_next;
164 p_unit->p_next->p_prev = p_unit->p_prev;
165 p_data->p_head = p_unit->p_next;
169 p_unit->p_prev = NULL;
170 p_unit->p_next = NULL;
171 ABTD_atomic_release_store_int(&p_unit->is_in_pool, 0);
175 pthread_mutex_unlock(&p_data->mutex);
182 ABTI_pool *p_pool = ABTI_pool_get_ptr(pool);
184 unit_t *p_unit = NULL;
187 pthread_mutex_lock(&p_data->mutex);
188 if (p_data->num_units > 0) {
189 p_unit = p_data->p_head;
190 if (p_data->num_units == 1) {
191 p_data->p_head = NULL;
192 p_data->p_tail = NULL;
194 p_unit->p_prev->p_next = p_unit->p_next;
195 p_unit->p_next->p_prev = p_unit->p_prev;
196 p_data->p_head = p_unit->p_next;
200 p_unit->p_prev = NULL;
201 p_unit->p_next = NULL;
202 ABTD_atomic_release_store_int(&p_unit->is_in_pool, 0);
206 pthread_mutex_unlock(&p_data->mutex);
213 ABTI_pool *p_pool = ABTI_pool_get_ptr(pool);
215 unit_t *p_unit = (unit_t *)unit;
217 ABTI_CHECK_TRUE_RET(p_data->num_units != 0,
ABT_ERR_POOL);
218 ABTI_CHECK_TRUE_RET(ABTD_atomic_acquire_load_int(&p_unit->is_in_pool) == 1,
221 pthread_mutex_lock(&p_data->mutex);
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 if (p_unit == p_data->p_head) {
229 p_data->p_head = p_unit->p_next;
230 }
else if (p_unit == p_data->p_tail) {
231 p_data->p_tail = p_unit->p_prev;
236 ABTD_atomic_release_store_int(&p_unit->is_in_pool, 0);
237 pthread_mutex_unlock(&p_data->mutex);
239 p_unit->p_prev = NULL;
240 p_unit->p_next = NULL;
248 ABTI_pool *p_pool = ABTI_pool_get_ptr(pool);
251 pthread_mutex_lock(&p_data->mutex);
253 size_t num_units = p_data->num_units;
254 unit_t *p_unit = p_data->p_head;
255 while (num_units--) {
259 p_unit = p_unit->p_next;
262 pthread_mutex_unlock(&p_data->mutex);
271 unit_t *p_unit = (unit_t *)unit;
278 unit_t *p_unit = (unit_t *)unit;
280 h_thread = p_unit->handle.thread;
290 unit_t *p_unit = (unit_t *)unit;
292 h_task = p_unit->handle.task;
301 unit_t *p_unit = (unit_t *)unit;
302 return ABTD_atomic_acquire_load_int(&p_unit->is_in_pool) ?
ABT_TRUE 308 ABTI_thread *p_thread = ABTI_thread_get_ptr(thread);
309 unit_t *p_unit = &p_thread->unit_def;
310 p_unit->p_prev = NULL;
311 p_unit->p_next = NULL;
312 ABTD_atomic_relaxed_store_int(&p_unit->is_in_pool, 0);
313 p_unit->handle.thread = thread;
321 ABTI_task *p_task = ABTI_task_get_ptr(task);
322 unit_t *p_unit = &p_task->unit_def;
323 p_unit->p_prev = NULL;
324 p_unit->p_next = NULL;
325 ABTD_atomic_relaxed_store_int(&p_unit->is_in_pool, 0);
326 p_unit->handle.task = task;
static ABT_unit unit_create_from_thread(ABT_thread thread)
struct ABT_unit_opaque * ABT_unit
ABT_unit_get_task_fn u_get_task
struct ABT_task_opaque * ABT_task
static ABT_unit pool_pop_timedwait(ABT_pool pool, double abstime_secs)
static void * ABTU_malloc(size_t size)
ABT_unit_get_thread_fn u_get_thread
static size_t pool_get_size(ABT_pool pool)
static int pool_print_all(ABT_pool pool, void *arg, void(*print_fn)(void *, ABT_unit))
static ABT_unit unit_create_from_task(ABT_task task)
struct ABT_pool_opaque * ABT_pool
ABT_unit_is_in_pool_fn u_is_in_pool
static ABT_unit_type unit_get_type(ABT_unit unit)
static ABT_unit pool_pop(ABT_pool pool)
static int pool_remove(ABT_pool pool, ABT_unit unit)
static int pool_init(ABT_pool pool, ABT_pool_config config)
struct ABT_thread_opaque * ABT_thread
static data_t * pool_get_data_ptr(void *p_data)
static int pool_free(ABT_pool pool)
static void unit_free(ABT_unit *unit)
static void convert_double_sec_to_timespec(struct timespec *ts_out, double seconds)
static ABT_task unit_get_task(ABT_unit unit)
ABT_unit_create_from_task_fn u_create_from_task
ABT_unit_create_from_thread_fn u_create_from_thread
static ABT_bool unit_is_in_pool(ABT_unit unit)
static ABT_thread unit_get_thread(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 void ABTU_free(void *ptr)
ABT_pool_remove_fn p_remove
ABT_pool_print_all_fn p_print_all
static void pool_push(ABT_pool pool, ABT_unit unit)
ABT_pool_pop_timedwait_fn p_pop_timedwait