ARGOBOTS  dce6e727ffc4ca5b3ffc04cb9517c6689be51ec5
pool_user_def.c
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 #include "abti.h"
7 
8 #include <stdlib.h>
9 #include <stdarg.h>
10 #include <string.h>
11 
51  ABT_pool_user_free_unit_fn p_free_unit,
52  ABT_pool_user_is_empty_fn p_is_empty,
54  ABT_pool_user_push_fn p_push,
55  ABT_pool_user_def *newdef)
56 {
57  ABTI_UB_ASSERT(ABTI_initialized());
58  ABTI_UB_ASSERT(newdef);
59  ABTI_UB_ASSERT(p_create_unit);
60  ABTI_UB_ASSERT(p_free_unit);
61  ABTI_UB_ASSERT(p_is_empty);
62  ABTI_UB_ASSERT(p_pop);
63  ABTI_UB_ASSERT(p_push);
64 
65  ABTI_pool_user_def *p_newdef;
66  int abt_errno =
67  ABTU_calloc(1, sizeof(ABTI_pool_user_def), (void **)&p_newdef);
68  ABTI_CHECK_ERROR(abt_errno);
69 
70  ABTI_UB_ASSERT(p_newdef->symbol == NULL); /* This value must be NULL. */
71  /* Set values */
72  p_newdef->required_def.p_create_unit = p_create_unit;
73  p_newdef->required_def.p_free_unit = p_free_unit;
74  p_newdef->required_def.p_is_empty = p_is_empty;
75  p_newdef->required_def.p_pop = p_pop;
76  p_newdef->required_def.p_push = p_push;
77 
78  *newdef = ABTI_pool_user_def_get_handle(p_newdef);
79  return ABT_SUCCESS;
80 }
81 
105 {
106  ABTI_UB_ASSERT(ABTI_initialized());
107  ABTI_UB_ASSERT(def);
108 
109  ABT_pool_user_def h_def = *def;
110  ABTI_pool_user_def *p_def = ABTI_pool_user_def_get_ptr(h_def);
111  ABTI_CHECK_NULL_POOL_USER_DEF_PTR(p_def);
112 
113  /* Free the memory */
114  ABTU_free(p_def);
115  *def = ABT_POOL_USER_DEF_NULL;
116  return ABT_SUCCESS;
117 }
118 
143  ABT_pool_user_init_fn p_init)
144 {
145  ABTI_UB_ASSERT(ABTI_initialized());
146 
147  ABTI_pool_user_def *p_def = ABTI_pool_user_def_get_ptr(def);
148  ABTI_CHECK_NULL_POOL_USER_DEF_PTR(p_def);
149 
150  p_def->optional_def.p_init = p_init;
151  return ABT_SUCCESS;
152 }
153 
178  ABT_pool_user_free_fn p_free)
179 {
180  ABTI_UB_ASSERT(ABTI_initialized());
181 
182  ABTI_pool_user_def *p_def = ABTI_pool_user_def_get_ptr(def);
183  ABTI_CHECK_NULL_POOL_USER_DEF_PTR(p_def);
184 
185  p_def->optional_def.p_free = p_free;
186  return ABT_SUCCESS;
187 }
188 
213  ABT_pool_user_get_size_fn p_get_size)
214 {
215  ABTI_UB_ASSERT(ABTI_initialized());
216 
217  ABTI_pool_user_def *p_def = ABTI_pool_user_def_get_ptr(def);
218  ABTI_CHECK_NULL_POOL_USER_DEF_PTR(p_def);
219 
220  p_def->optional_def.p_get_size = p_get_size;
221  return ABT_SUCCESS;
222 }
223 
248  ABT_pool_user_pop_wait_fn p_pop_wait)
249 {
250  ABTI_UB_ASSERT(ABTI_initialized());
251 
252  ABTI_pool_user_def *p_def = ABTI_pool_user_def_get_ptr(def);
253  ABTI_CHECK_NULL_POOL_USER_DEF_PTR(p_def);
254 
255  p_def->optional_def.p_pop_wait = p_pop_wait;
256  return ABT_SUCCESS;
257 }
258 
283  ABT_pool_user_pop_many_fn p_pop_many)
284 {
285  ABTI_UB_ASSERT(ABTI_initialized());
286 
287  ABTI_pool_user_def *p_def = ABTI_pool_user_def_get_ptr(def);
288  ABTI_CHECK_NULL_POOL_USER_DEF_PTR(p_def);
289 
290  p_def->optional_def.p_pop_many = p_pop_many;
291  return ABT_SUCCESS;
292 }
293 
318  ABT_pool_user_push_many_fn p_push_many)
319 {
320  ABTI_UB_ASSERT(ABTI_initialized());
321 
322  ABTI_pool_user_def *p_def = ABTI_pool_user_def_get_ptr(def);
323  ABTI_CHECK_NULL_POOL_USER_DEF_PTR(p_def);
324 
325  p_def->optional_def.p_push_many = p_push_many;
326  return ABT_SUCCESS;
327 }
328 
353  ABT_pool_user_print_all_fn p_print_all)
354 {
355  ABTI_UB_ASSERT(ABTI_initialized());
356 
357  ABTI_pool_user_def *p_def = ABTI_pool_user_def_get_ptr(def);
358  ABTI_CHECK_NULL_POOL_USER_DEF_PTR(p_def);
359 
360  p_def->optional_def.p_print_all = p_print_all;
361  return ABT_SUCCESS;
362 }
363 
364 /*****************************************************************************/
365 /* Private APIs */
366 /*****************************************************************************/
367 
368 ABT_bool ABTI_pool_user_def_is_new(const ABT_pool_user_def def)
369 {
370  /* If def points to ABT_pool_def, this u_create_from_thread not be NULL.
371  * Otherwise, it is "symbol", so it must be NULL. */
372  return def->u_create_from_thread ? ABT_FALSE : ABT_TRUE;
373 }
ABT_pool_user_def_set_print_all
int ABT_pool_user_def_set_print_all(ABT_pool_user_def def, ABT_pool_user_print_all_fn p_print_all)
Register a print-all function to a pool definition.
Definition: pool_user_def.c:352
ABT_bool
int ABT_bool
Boolean type.
Definition: abt.h:1043
ABT_pool_user_def_free
int ABT_pool_user_def_free(ABT_pool_user_def *def)
Free a pool definition.
Definition: pool_user_def.c:104
ABT_pool_user_def_set_get_size
int ABT_pool_user_def_set_get_size(ABT_pool_user_def def, ABT_pool_user_get_size_fn p_get_size)
Register a size inquiry function to a pool definition.
Definition: pool_user_def.c:212
ABT_pool_user_print_all_fn
void(* ABT_pool_user_print_all_fn)(ABT_pool, void *arg, void(*)(void *, ABT_thread))
Function that applies a user-given function to all work units in a pool.
Definition: abt.h:2023
ABT_pool_user_create_unit_fn
ABT_unit(* ABT_pool_user_create_unit_fn)(ABT_pool, ABT_thread)
Function that creates an ABT_unit handle that is associated with an ABT_thread handle.
Definition: abt.h:1807
ABT_pool_user_push_many_fn
void(* ABT_pool_user_push_many_fn)(ABT_pool, const ABT_unit *, size_t, ABT_pool_context)
Function that pushes work units to a pool.
Definition: abt.h:2003
ABT_pool_user_get_size_fn
size_t(* ABT_pool_user_get_size_fn)(ABT_pool)
Function that returns the number of work units in a pool.
Definition: abt.h:1927
ABT_pool_user_def_create
int ABT_pool_user_def_create(ABT_pool_user_create_unit_fn p_create_unit, ABT_pool_user_free_unit_fn p_free_unit, ABT_pool_user_is_empty_fn p_is_empty, ABT_pool_user_pop_fn p_pop, ABT_pool_user_push_fn p_push, ABT_pool_user_def *newdef)
Create a new pool definition.
Definition: pool_user_def.c:50
ABT_pool_user_push_fn
void(* ABT_pool_user_push_fn)(ABT_pool, ABT_unit, ABT_pool_context)
Function that pushes a work unit to a pool.
Definition: abt.h:1879
ABT_pool_user_def_set_pop_wait
int ABT_pool_user_def_set_pop_wait(ABT_pool_user_def def, ABT_pool_user_pop_wait_fn p_pop_wait)
Register a pop-wait function to a pool definition.
Definition: pool_user_def.c:247
abti.h
ABT_pool_user_def_set_init
int ABT_pool_user_def_set_init(ABT_pool_user_def def, ABT_pool_user_init_fn p_init)
Register a pool initialization function to a pool definition.
Definition: pool_user_def.c:142
ABT_pool_def
A struct that defines a pool.
Definition: abt.h:2049
ABT_pool_user_pop_many_fn
void(* ABT_pool_user_pop_many_fn)(ABT_pool, ABT_thread *, size_t, size_t *, ABT_pool_context)
Function that pops work units from a pool.
Definition: abt.h:1978
ABT_pool_user_def_set_free
int ABT_pool_user_def_set_free(ABT_pool_user_def def, ABT_pool_user_free_fn p_free)
Register a pool finalization function to a pool definition.
Definition: pool_user_def.c:177
ABTU_calloc
static ABTU_ret_err int ABTU_calloc(size_t num, size_t size, void **p_ptr)
Definition: abtu.h:244
ABT_SUCCESS
#define ABT_SUCCESS
Error code: the routine returns successfully.
Definition: abt.h:92
ABT_pool_user_pop_wait_fn
ABT_thread(* ABT_pool_user_pop_wait_fn)(ABT_pool, double, ABT_pool_context)
Function that pops a work unit from a pool with wait.
Definition: abt.h:1950
ABT_pool_user_free_fn
void(* ABT_pool_user_free_fn)(ABT_pool)
Function that frees a pool.
Definition: abt.h:1911
ABT_TRUE
#define ABT_TRUE
True constant for ABT_bool.
Definition: abt.h:784
ABT_pool_user_free_unit_fn
void(* ABT_pool_user_free_unit_fn)(ABT_pool, ABT_unit)
Function that frees an ABT_unit handle.
Definition: abt.h:1824
ABT_FALSE
#define ABT_FALSE
False constant for ABT_bool.
Definition: abt.h:786
ABT_pool_user_is_empty_fn
ABT_bool(* ABT_pool_user_is_empty_fn)(ABT_pool)
Function that returns if a pool is empty.
Definition: abt.h:1840
ABTU_free
static void ABTU_free(void *ptr)
Definition: abtu.h:228
ABT_pool_user_pop_fn
ABT_thread(* ABT_pool_user_pop_fn)(ABT_pool, ABT_pool_context)
Function that pops a work unit from a pool.
Definition: abt.h:1859
ABT_pool_def::u_create_from_thread
ABT_unit_create_from_thread_fn u_create_from_thread
Function that creates an ABT_unit handle that is associated with an ABT_thread handle.
Definition: abt.h:2128
ABT_pool_user_def_set_push_many
int ABT_pool_user_def_set_push_many(ABT_pool_user_def def, ABT_pool_user_push_many_fn p_push_many)
Register a push-many function to a pool definition.
Definition: pool_user_def.c:317
ABT_POOL_USER_DEF_NULL
#define ABT_POOL_USER_DEF_NULL
Definition: abt.h:1118
ABT_pool_user_init_fn
int(* ABT_pool_user_init_fn)(ABT_pool, ABT_pool_config)
Function that creates a pool.
Definition: abt.h:1896
ABT_pool_user_def_set_pop_many
int ABT_pool_user_def_set_pop_many(ABT_pool_user_def def, ABT_pool_user_pop_many_fn p_pop_many)
Register a pop-many function to a pool definition.
Definition: pool_user_def.c:282