ARGOBOTS  8bef54a19d7b3e50f977f85716578b627bf37d9c
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 {
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. */
63  ABTD_atomic_relaxed_store_int(&p_thread->state, ABT_THREAD_STATE_READY);
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 
85 static inline ABT_unit ABTI_pool_pop_timedwait(ABTI_pool *p_pool,
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 {
110  ABTD_atomic_fetch_add_int32(&p_pool->num_scheds, 1);
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 {
117  ABTI_ASSERT(ABTD_atomic_acquire_load_int32(&p_pool->num_scheds) > 0);
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 */
ABT_THREAD_STATE_READY
@ ABT_THREAD_STATE_READY
Definition: abt.h:417
ABT_pool
struct ABT_pool_opaque * ABT_pool
Pool handle type.
Definition: abt.h:841
ABT_POOL_NULL
#define ABT_POOL_NULL
Definition: abt.h:1059
ABT_unit
struct ABT_unit_opaque * ABT_unit
Work unit handle type for scheduling.
Definition: abt.h:869
ABTU_ret_err
#define ABTU_ret_err
Definition: abtu.h:155
LOG_DEBUG_POOL_POP
#define LOG_DEBUG_POOL_POP(p_pool, unit)
Definition: abti_log.h:30
LOG_DEBUG_POOL_REMOVE
#define LOG_DEBUG_POOL_REMOVE(p_pool, unit)
Definition: abti_log.h:29