ARGOBOTS  dce6e727ffc4ca5b3ffc04cb9517c6689be51ec5
abti_pool.h
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 #ifndef ABTI_POOL_H_INCLUDED
7 #define ABTI_POOL_H_INCLUDED
8 
9 /* Inlined functions for Pool */
10 
11 static inline ABTI_pool *ABTI_pool_get_ptr(ABT_pool pool)
12 {
13 #ifndef ABT_CONFIG_DISABLE_ERROR_CHECK
14  ABTI_pool *p_pool;
15  if (pool == ABT_POOL_NULL) {
16  p_pool = NULL;
17  } else {
18  p_pool = (ABTI_pool *)pool;
19  }
20  return p_pool;
21 #else
22  return (ABTI_pool *)pool;
23 #endif
24 }
25 
26 static inline ABT_pool ABTI_pool_get_handle(ABTI_pool *p_pool)
27 {
28 #ifndef ABT_CONFIG_DISABLE_ERROR_CHECK
29  ABT_pool h_pool;
30  if (p_pool == NULL) {
31  h_pool = ABT_POOL_NULL;
32  } else {
33  h_pool = (ABT_pool)p_pool;
34  }
35  return h_pool;
36 #else
37  return (ABT_pool)p_pool;
38 #endif
39 }
40 
41 /* A ULT is blocked and is waiting for going back to this pool */
42 static inline void ABTI_pool_inc_num_blocked(ABTI_pool *p_pool)
43 {
45 }
46 
47 /* A blocked ULT is back in the pool */
48 static inline void ABTI_pool_dec_num_blocked(ABTI_pool *p_pool)
49 {
51 }
52 
53 static inline void ABTI_pool_push(ABTI_pool *p_pool, ABT_unit unit,
54  ABT_pool_context context)
55 {
56  /* Push unit into pool */
57  LOG_DEBUG_POOL_PUSH(p_pool, unit);
58  p_pool->required_def.p_push(ABTI_pool_get_handle(p_pool), unit, context);
59 }
60 
61 static inline void ABTI_pool_add_thread(ABTI_thread *p_thread,
62  ABT_pool_context context)
63 {
64  /* Set the ULT's state as READY. The relaxed version is used since the state
65  * is synchronized by the following pool operation. */
67  /* Add the ULT to the associated pool */
68  ABTI_pool_push(p_thread->p_pool, p_thread->unit, context);
69 }
70 
71 ABTU_ret_err static inline int ABTI_pool_remove(ABTI_pool *p_pool,
72  ABT_unit unit)
73 {
74  LOG_DEBUG_POOL_REMOVE(p_pool, unit);
76  return p_pool->deprecated_def.p_remove(ABTI_pool_get_handle(p_pool), unit);
77 }
78 
79 static inline ABT_thread ABTI_pool_pop_wait(ABTI_pool *p_pool, double time_secs,
80  ABT_pool_context context)
81 {
83  ABT_thread thread =
84  p_pool->optional_def.p_pop_wait(ABTI_pool_get_handle(p_pool), time_secs,
85  context);
86  LOG_DEBUG_POOL_POP(p_pool, thread);
87  return thread;
88 }
89 
90 /* Defined in pool.c */
91 ABT_thread ABTI_pool_pop_timedwait(ABTI_pool *p_pool, double abstime_secs);
92 
93 static inline ABT_thread ABTI_pool_pop(ABTI_pool *p_pool,
94  ABT_pool_context context)
95 {
96  ABT_thread thread =
97  p_pool->required_def.p_pop(ABTI_pool_get_handle(p_pool), context);
98  LOG_DEBUG_POOL_POP(p_pool, thread);
99  return thread;
100 }
101 
102 static inline void ABTI_pool_pop_many(ABTI_pool *p_pool, ABT_thread *threads,
103  size_t len, size_t *num,
104  ABT_pool_context context)
105 {
107  p_pool->optional_def.p_pop_many(ABTI_pool_get_handle(p_pool), threads, len,
108  num, context);
109  LOG_DEBUG_POOL_POP_MANY(p_pool, threads, *num);
110 }
111 
112 static inline void ABTI_pool_push_many(ABTI_pool *p_pool, const ABT_unit *units,
113  size_t num, ABT_pool_context context)
114 {
116  p_pool->optional_def.p_push_many(ABTI_pool_get_handle(p_pool), units, num,
117  context);
118  LOG_DEBUG_POOL_PUSH_MANY(p_pool, units, num);
119 }
120 
121 /* Increase num_scheds to mark the pool as having another scheduler. If the
122  * pool is not available, it returns ABT_ERR_INV_POOL_ACCESS. */
123 static inline void ABTI_pool_retain(ABTI_pool *p_pool)
124 {
126 }
127 
128 /* Decrease the num_scheds to release this pool from a scheduler. Call when
129  * the pool is removed from a scheduler or when it stops. */
130 static inline int32_t ABTI_pool_release(ABTI_pool *p_pool)
131 {
133  return ABTD_atomic_fetch_sub_int32(&p_pool->num_scheds, 1) - 1;
134 }
135 
136 static inline ABT_bool ABTI_pool_is_empty(ABTI_pool *p_pool)
137 {
138  return p_pool->required_def.p_is_empty(ABTI_pool_get_handle(p_pool));
139 }
140 
141 static inline size_t ABTI_pool_get_size(ABTI_pool *p_pool)
142 {
144  return p_pool->optional_def.p_get_size(ABTI_pool_get_handle(p_pool));
145 }
146 
147 static inline size_t ABTI_pool_get_total_size(ABTI_pool *p_pool)
148 {
149  size_t total_size;
150  total_size = ABTI_pool_get_size(p_pool);
151  total_size += ABTD_atomic_acquire_load_int32(&p_pool->num_blocked);
152  return total_size;
153 }
154 
155 #endif /* ABTI_POOL_H_INCLUDED */
ABTI_pool_optional_def::p_get_size
ABT_pool_user_get_size_fn p_get_size
Definition: abti.h:361
ABTI_pool::num_blocked
ABTD_atomic_int32 num_blocked
Definition: abti.h:395
ABTI_pool_deprecated_def::p_remove
ABT_pool_remove_fn p_remove
Definition: abti.h:373
ABT_bool
int ABT_bool
Boolean type.
Definition: abt.h:1043
ABT_pool_context
uint64_t ABT_pool_context
A pool context value.
Definition: abt.h:1566
ABT_THREAD_STATE_READY
@ ABT_THREAD_STATE_READY
Definition: abt.h:427
ABT_thread
struct ABT_thread_opaque * ABT_thread
Work unit handle type.
Definition: abt.h:932
ABTI_pool_required_def::p_push
ABT_pool_user_push_fn p_push
Definition: abti.h:354
ABTI_pool_required_def::p_pop
ABT_pool_user_pop_fn p_pop
Definition: abti.h:353
ABTI_thread::unit
ABT_unit unit
Definition: abti.h:427
ABTI_pool_get_size
static size_t ABTI_pool_get_size(ABTI_pool *p_pool)
Definition: abti_pool.h:141
ABTI_thread
Definition: abti.h:422
ABT_pool
struct ABT_pool_opaque * ABT_pool
Pool handle type.
Definition: abt.h:878
ABTD_atomic_fetch_add_int32
static int32_t ABTD_atomic_fetch_add_int32(ABTD_atomic_int32 *ptr, int32_t v)
Definition: abtd_atomic.h:447
ABTI_pool_pop
static ABT_thread ABTI_pool_pop(ABTI_pool *p_pool, ABT_pool_context context)
Definition: abti_pool.h:93
ABTD_atomic_acquire_load_int32
static int32_t ABTD_atomic_acquire_load_int32(const ABTD_atomic_int32 *ptr)
Definition: abtd_atomic.h:911
ABTI_pool
Definition: abti.h:389
ABT_POOL_NULL
#define ABT_POOL_NULL
Definition: abt.h:1102
LOG_DEBUG_POOL_POP
#define LOG_DEBUG_POOL_POP(p_pool, thread)
Definition: abti_log.h:39
ABTI_thread::state
ABTD_atomic_int state
Definition: abti.h:432
ABTI_pool_push_many
static void ABTI_pool_push_many(ABTI_pool *p_pool, const ABT_unit *units, size_t num, ABT_pool_context context)
Definition: abti_pool.h:112
ABTI_pool_pop_wait
static ABT_thread ABTI_pool_pop_wait(ABTI_pool *p_pool, double time_secs, ABT_pool_context context)
Definition: abti_pool.h:79
LOG_DEBUG_POOL_PUSH
#define LOG_DEBUG_POOL_PUSH(p_pool, unit)
Definition: abti_log.h:33
ABTI_pool_remove
static ABTU_ret_err int ABTI_pool_remove(ABTI_pool *p_pool, ABT_unit unit)
Definition: abti_pool.h:71
ABTD_atomic_relaxed_store_int
static void ABTD_atomic_relaxed_store_int(ABTD_atomic_int *ptr, int val)
Definition: abtd_atomic.h:996
ABTI_pool_optional_def::p_pop_wait
ABT_pool_user_pop_wait_fn p_pop_wait
Definition: abti.h:362
ABTI_pool_get_total_size
static size_t ABTI_pool_get_total_size(ABTI_pool *p_pool)
Definition: abti_pool.h:147
ABT_unit
struct ABT_unit_opaque * ABT_unit
Work unit handle type for scheduling.
Definition: abt.h:911
ABTI_ASSERT
#define ABTI_ASSERT(cond)
Definition: abti_error.h:12
ABTU_ret_err
#define ABTU_ret_err
Definition: abtu.h:155
ABTI_pool::required_def
ABTI_pool_required_def required_def
Definition: abti.h:399
ABTI_pool_optional_def::p_push_many
ABT_pool_user_push_many_fn p_push_many
Definition: abti.h:364
ABTI_pool::deprecated_def
ABTI_pool_deprecated_def deprecated_def
Definition: abti.h:401
LOG_DEBUG_POOL_POP_MANY
#define LOG_DEBUG_POOL_POP_MANY(p_pool, threads, num)
Definition: abti_log.h:42
LOG_DEBUG_POOL_PUSH_MANY
#define LOG_DEBUG_POOL_PUSH_MANY(p_pool, units, num)
Definition: abti_log.h:45
ABTI_pool_pop_timedwait
ABT_thread ABTI_pool_pop_timedwait(ABTI_pool *p_pool, double abstime_secs)
Definition: pool.c:1442
ABTI_pool_get_ptr
static ABTI_pool * ABTI_pool_get_ptr(ABT_pool pool)
Definition: abti_pool.h:11
ABTI_pool_add_thread
static void ABTI_pool_add_thread(ABTI_thread *p_thread, ABT_pool_context context)
Definition: abti_pool.h:61
ABTI_pool_pop_many
static void ABTI_pool_pop_many(ABTI_pool *p_pool, ABT_thread *threads, size_t len, size_t *num, ABT_pool_context context)
Definition: abti_pool.h:102
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
ABTI_pool_push
static void ABTI_pool_push(ABTI_pool *p_pool, ABT_unit unit, ABT_pool_context context)
Definition: abti_pool.h:53
ABTI_pool_inc_num_blocked
static void ABTI_pool_inc_num_blocked(ABTI_pool *p_pool)
Definition: abti_pool.h:42
ABTI_pool_is_empty
static ABT_bool ABTI_pool_is_empty(ABTI_pool *p_pool)
Definition: abti_pool.h:136
ABTI_pool::optional_def
ABTI_pool_optional_def optional_def
Definition: abti.h:400
ABTI_thread::p_pool
ABTI_pool * p_pool
Definition: abti.h:434
ABTI_pool_release
static int32_t ABTI_pool_release(ABTI_pool *p_pool)
Definition: abti_pool.h:130
ABTI_pool_required_def::p_is_empty
ABT_pool_user_is_empty_fn p_is_empty
Definition: abti.h:352
ABTI_pool_retain
static void ABTI_pool_retain(ABTI_pool *p_pool)
Definition: abti_pool.h:123
ABTI_pool::num_scheds
ABTD_atomic_int32 num_scheds
Definition: abti.h:394
LOG_DEBUG_POOL_REMOVE
#define LOG_DEBUG_POOL_REMOVE(p_pool, unit)
Definition: abti_log.h:36
ABTI_pool_get_handle
static ABT_pool ABTI_pool_get_handle(ABTI_pool *p_pool)
Definition: abti_pool.h:26
ABTD_atomic_fetch_sub_int32
static int32_t ABTD_atomic_fetch_sub_int32(ABTD_atomic_int32 *ptr, int32_t v)
Definition: abtd_atomic.h:505
ABTI_pool_dec_num_blocked
static void ABTI_pool_dec_num_blocked(ABTI_pool *p_pool)
Definition: abti_pool.h:48