ARGOBOTS  1.1
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 {
55  /* Push unit into pool */
56  p_pool->p_push(ABTI_pool_get_handle(p_pool), unit);
57 }
58 
59 static inline void ABTI_pool_add_thread(ABTI_thread *p_thread)
60 {
61  /* Set the ULT's state as READY. The relaxed version is used since the state
62  * is synchronized by the following pool operation. */
64  /* Add the ULT to the associated pool */
65  ABTI_pool_push(p_thread->p_pool, p_thread->unit);
66 }
67 
68 ABTU_ret_err static inline int ABTI_pool_remove(ABTI_pool *p_pool,
69  ABT_unit unit)
70 {
71  LOG_DEBUG_POOL_REMOVE(p_pool, unit);
72  return p_pool->p_remove(ABTI_pool_get_handle(p_pool), unit);
73 }
74 
75 static inline ABT_unit ABTI_pool_pop_wait(ABTI_pool *p_pool, double time_secs)
76 {
77  ABT_unit unit;
78 
79  unit = p_pool->p_pop_wait(ABTI_pool_get_handle(p_pool), time_secs);
80  LOG_DEBUG_POOL_POP(p_pool, unit);
81 
82  return unit;
83 }
84 
86  double abstime_secs)
87 {
88  ABT_unit unit;
89 
90  unit = p_pool->p_pop_timedwait(ABTI_pool_get_handle(p_pool), abstime_secs);
91  LOG_DEBUG_POOL_POP(p_pool, unit);
92 
93  return unit;
94 }
95 
96 static inline ABT_unit ABTI_pool_pop(ABTI_pool *p_pool)
97 {
98  ABT_unit unit;
99 
100  unit = p_pool->p_pop(ABTI_pool_get_handle(p_pool));
101  LOG_DEBUG_POOL_POP(p_pool, unit);
102 
103  return unit;
104 }
105 
106 /* Increase num_scheds to mark the pool as having another scheduler. If the
107  * pool is not available, it returns ABT_ERR_INV_POOL_ACCESS. */
108 static inline void ABTI_pool_retain(ABTI_pool *p_pool)
109 {
111 }
112 
113 /* Decrease the num_scheds to release this pool from a scheduler. Call when
114  * the pool is removed from a scheduler or when it stops. */
115 static inline int32_t ABTI_pool_release(ABTI_pool *p_pool)
116 {
118  return ABTD_atomic_fetch_sub_int32(&p_pool->num_scheds, 1) - 1;
119 }
120 
121 static inline size_t ABTI_pool_get_size(ABTI_pool *p_pool)
122 {
123  return p_pool->p_get_size(ABTI_pool_get_handle(p_pool));
124 }
125 
126 static inline size_t ABTI_pool_get_total_size(ABTI_pool *p_pool)
127 {
128  size_t total_size;
129  total_size = ABTI_pool_get_size(p_pool);
130  total_size += ABTD_atomic_acquire_load_int32(&p_pool->num_blocked);
131  return total_size;
132 }
133 
134 #endif /* ABTI_POOL_H_INCLUDED */
ABTI_pool::num_blocked
ABTD_atomic_int32 num_blocked
Definition: abti.h:333
ABT_THREAD_STATE_READY
@ ABT_THREAD_STATE_READY
Definition: abt.h:417
ABTI_thread::unit
ABT_unit unit
Definition: abti.h:376
ABTI_pool_push
static void ABTI_pool_push(ABTI_pool *p_pool, ABT_unit unit)
Definition: abti_pool.h:53
ABTI_pool_get_size
static size_t ABTI_pool_get_size(ABTI_pool *p_pool)
Definition: abti_pool.h:121
ABTI_thread
Definition: abti.h:371
ABTI_pool::p_push
ABT_pool_push_fn p_push
Definition: abti.h:345
ABT_pool
struct ABT_pool_opaque * ABT_pool
Pool handle type.
Definition: abt.h:841
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
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:327
ABT_POOL_NULL
#define ABT_POOL_NULL
Definition: abt.h:1059
ABTI_thread::state
ABTD_atomic_int state
Definition: abti.h:381
ABTI_pool_add_thread
static void ABTI_pool_add_thread(ABTI_thread *p_thread)
Definition: abti_pool.h:59
ABTI_pool::p_pop_wait
ABT_pool_pop_wait_fn p_pop_wait
Definition: abti.h:347
ABTI_pool::p_pop
ABT_pool_pop_fn p_pop
Definition: abti.h:346
ABTI_pool_remove
static ABTU_ret_err int ABTI_pool_remove(ABTI_pool *p_pool, ABT_unit unit)
Definition: abti_pool.h:68
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::p_remove
ABT_pool_remove_fn p_remove
Definition: abti.h:349
ABTI_pool_get_total_size
static size_t ABTI_pool_get_total_size(ABTI_pool *p_pool)
Definition: abti_pool.h:126
ABT_unit
struct ABT_unit_opaque * ABT_unit
Work unit handle type for scheduling.
Definition: abt.h:869
ABTI_ASSERT
#define ABTI_ASSERT(cond)
Definition: abti_error.h:12
ABTI_pool::p_get_size
ABT_pool_get_size_fn p_get_size
Definition: abti.h:344
ABTU_ret_err
#define ABTU_ret_err
Definition: abtu.h:146
LOG_DEBUG_POOL_POP
#define LOG_DEBUG_POOL_POP(p_pool, unit)
Definition: abti_log.h:30
ABTI_pool_get_ptr
static ABTI_pool * ABTI_pool_get_ptr(ABT_pool pool)
Definition: abti_pool.h:11
ABTI_pool_pop
static ABT_unit ABTI_pool_pop(ABTI_pool *p_pool)
Definition: abti_pool.h:96
ABTI_pool_pop_wait
static ABT_unit ABTI_pool_pop_wait(ABTI_pool *p_pool, double time_secs)
Definition: abti_pool.h:75
ABTI_pool_inc_num_blocked
static void ABTI_pool_inc_num_blocked(ABTI_pool *p_pool)
Definition: abti_pool.h:42
ABTI_pool_pop_timedwait
static ABT_unit ABTI_pool_pop_timedwait(ABTI_pool *p_pool, double abstime_secs)
Definition: abti_pool.h:85
ABTI_thread::p_pool
ABTI_pool * p_pool
Definition: abti.h:383
ABTI_pool_release
static int32_t ABTI_pool_release(ABTI_pool *p_pool)
Definition: abti_pool.h:115
ABTI_pool_retain
static void ABTI_pool_retain(ABTI_pool *p_pool)
Definition: abti_pool.h:108
ABTI_pool::num_scheds
ABTD_atomic_int32 num_scheds
Definition: abti.h:332
LOG_DEBUG_POOL_REMOVE
#define LOG_DEBUG_POOL_REMOVE(p_pool, unit)
Definition: abti_log.h:29
ABTI_pool::p_pop_timedwait
ABT_pool_pop_timedwait_fn p_pop_timedwait
Definition: abti.h:348
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