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 {
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 {
107  ABTI_UB_ASSERT(def);
108 
109  ABT_pool_user_def h_def = *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 {
146 
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 {
181 
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 {
216 
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 {
251 
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 {
286 
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 {
321 
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 {
356 
359 
360  p_def->optional_def.p_print_all = p_print_all;
361  return ABT_SUCCESS;
362 }
363 
364 /*****************************************************************************/
365 /* Private APIs */
366 /*****************************************************************************/
367 
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 }
ABTI_pool_optional_def::p_get_size
ABT_pool_user_get_size_fn p_get_size
Definition: abti.h:361
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
ABTI_pool_optional_def::p_init
ABT_pool_user_init_fn p_init
Definition: abti.h:359
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
ABTI_pool_optional_def::p_print_all
ABT_pool_user_print_all_fn p_print_all
Definition: abti.h:365
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
ABTI_pool_user_def_is_new
ABT_bool ABTI_pool_user_def_is_new(const ABT_pool_user_def def)
Definition: pool_user_def.c:368
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
ABTI_pool_user_def_get_ptr
static ABTI_pool_user_def * ABTI_pool_user_def_get_ptr(ABT_pool_user_def def)
Definition: abti_pool_user_def.h:12
ABTI_CHECK_ERROR
#define ABTI_CHECK_ERROR(abt_errno)
Definition: abti_error.h:136
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
ABTI_CHECK_NULL_POOL_USER_DEF_PTR
#define ABTI_CHECK_NULL_POOL_USER_DEF_PTR(p)
Definition: abti_error.h:202
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
ABTI_pool_user_def::optional_def
ABTI_pool_optional_def optional_def
Definition: abti.h:415
ABTI_pool_optional_def::p_pop_wait
ABT_pool_user_pop_wait_fn p_pop_wait
Definition: abti.h:362
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
ABTI_initialized
ABT_bool ABTI_initialized(void)
Definition: global.c:187
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
ABTI_pool_optional_def::p_push_many
ABT_pool_user_push_many_fn p_push_many
Definition: abti.h:364
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
ABTI_UB_ASSERT
#define ABTI_UB_ASSERT(cond)
Definition: abti_error.h:19
ABTI_pool_optional_def::p_pop_many
ABT_pool_user_pop_many_fn p_pop_many
Definition: abti.h:363
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
ABTI_pool_user_def
Definition: abti.h:405
ABT_POOL_USER_DEF_NULL
#define ABT_POOL_USER_DEF_NULL
Definition: abt.h:1118
ABTI_pool_user_def_get_handle
static ABT_pool_user_def ABTI_pool_user_def_get_handle(ABTI_pool_user_def *p_def)
Definition: abti_pool_user_def.h:28
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
ABTI_pool_optional_def::p_free
ABT_pool_user_free_fn p_free
Definition: abti.h:360
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