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 {
44  ABTD_atomic_fetch_add_int32(&p_pool->num_blocked, 1);
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 {
50  ABTD_atomic_fetch_sub_int32(&p_pool->num_blocked, 1);
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. */
66  ABTD_atomic_relaxed_store_int(&p_thread->state, ABT_THREAD_STATE_READY);
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);
75  ABTI_UB_ASSERT(p_pool->deprecated_def.p_remove);
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 {
82  ABTI_UB_ASSERT(p_pool->optional_def.p_pop_wait);
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 {
106  ABTI_UB_ASSERT(p_pool->optional_def.p_pop_many);
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 {
115  ABTI_UB_ASSERT(p_pool->optional_def.p_push_many);
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 {
125  ABTD_atomic_fetch_add_int32(&p_pool->num_scheds, 1);
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 {
132  ABTI_ASSERT(ABTD_atomic_acquire_load_int32(&p_pool->num_scheds) > 0);
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 {
143  ABTI_UB_ASSERT(p_pool->optional_def.p_get_size);
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 */
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
ABT_pool
struct ABT_pool_opaque * ABT_pool
Pool handle type.
Definition: abt.h:878
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
LOG_DEBUG_POOL_PUSH
#define LOG_DEBUG_POOL_PUSH(p_pool, unit)
Definition: abti_log.h:33
ABT_unit
struct ABT_unit_opaque * ABT_unit
Work unit handle type for scheduling.
Definition: abt.h:911
ABTU_ret_err
#define ABTU_ret_err
Definition: abtu.h:155
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
LOG_DEBUG_POOL_REMOVE
#define LOG_DEBUG_POOL_REMOVE(p_pool, unit)
Definition: abti_log.h:36