ARGOBOTS  66b1c39742507d8df30e8d28c54839b961a14814
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Groups
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 /* The pool will receive a migrated ULT */
54 static inline void ABTI_pool_inc_num_migrations(ABTI_pool *p_pool)
55 {
56  ABTD_atomic_fetch_add_int32(&p_pool->num_migrations, 1);
57 }
58 
59 /* The pool has received a migrated ULT */
60 static inline void ABTI_pool_dec_num_migrations(ABTI_pool *p_pool)
61 {
62  ABTD_atomic_fetch_sub_int32(&p_pool->num_migrations, 1);
63 }
64 
65 static inline void ABTI_pool_push(ABTI_pool *p_pool, ABT_unit unit)
66 {
67  /* Push unit into pool */
68  p_pool->p_push(ABTI_pool_get_handle(p_pool), unit);
69 }
70 
71 static inline void ABTI_pool_add_thread(ABTI_thread *p_thread)
72 {
73  /* Set the ULT's state as READY. The relaxed version is used since the state
74  * is synchronized by the following pool operation. */
75  ABTD_atomic_relaxed_store_int(&p_thread->state, ABT_THREAD_STATE_READY);
76  /* Add the ULT to the associated pool */
77  ABTI_pool_push(p_thread->p_pool, p_thread->unit);
78 }
79 
80 ABTU_ret_err static inline int ABTI_pool_remove(ABTI_pool *p_pool,
81  ABT_unit unit)
82 {
83  LOG_DEBUG_POOL_REMOVE(p_pool, unit);
84  return p_pool->p_remove(ABTI_pool_get_handle(p_pool), unit);
85 }
86 
87 static inline ABT_unit ABTI_pool_pop_wait(ABTI_pool *p_pool, double time_secs)
88 {
89  ABT_unit unit;
90 
91  unit = p_pool->p_pop_wait(ABTI_pool_get_handle(p_pool), time_secs);
92  LOG_DEBUG_POOL_POP(p_pool, unit);
93 
94  return unit;
95 }
96 
97 static inline ABT_unit ABTI_pool_pop_timedwait(ABTI_pool *p_pool,
98  double abstime_secs)
99 {
100  ABT_unit unit;
101 
102  unit = p_pool->p_pop_timedwait(ABTI_pool_get_handle(p_pool), abstime_secs);
103  LOG_DEBUG_POOL_POP(p_pool, unit);
104 
105  return unit;
106 }
107 
108 static inline ABT_unit ABTI_pool_pop(ABTI_pool *p_pool)
109 {
110  ABT_unit unit;
111 
112  unit = p_pool->p_pop(ABTI_pool_get_handle(p_pool));
113  LOG_DEBUG_POOL_POP(p_pool, unit);
114 
115  return unit;
116 }
117 
118 /* Increase num_scheds to mark the pool as having another scheduler. If the
119  * pool is not available, it returns ABT_ERR_INV_POOL_ACCESS. */
120 static inline void ABTI_pool_retain(ABTI_pool *p_pool)
121 {
122  ABTD_atomic_fetch_add_int32(&p_pool->num_scheds, 1);
123 }
124 
125 /* Decrease the num_scheds to release this pool from a scheduler. Call when
126  * the pool is removed from a scheduler or when it stops. */
127 static inline int32_t ABTI_pool_release(ABTI_pool *p_pool)
128 {
129  ABTI_ASSERT(ABTD_atomic_acquire_load_int32(&p_pool->num_scheds) > 0);
130  return ABTD_atomic_fetch_sub_int32(&p_pool->num_scheds, 1) - 1;
131 }
132 
133 static inline size_t ABTI_pool_get_size(ABTI_pool *p_pool)
134 {
135  return p_pool->p_get_size(ABTI_pool_get_handle(p_pool));
136 }
137 
138 static inline size_t ABTI_pool_get_total_size(ABTI_pool *p_pool)
139 {
140  size_t total_size;
141  total_size = ABTI_pool_get_size(p_pool);
142  total_size += ABTD_atomic_acquire_load_int32(&p_pool->num_blocked);
143  total_size += ABTD_atomic_acquire_load_int32(&p_pool->num_migrations);
144  return total_size;
145 }
146 
147 #endif /* ABTI_POOL_H_INCLUDED */
struct ABT_unit_opaque * ABT_unit
Definition: abt.h:337
#define ABT_POOL_NULL
Definition: abt.h:413
struct ABT_pool_opaque * ABT_pool
Definition: abt.h:329
#define LOG_DEBUG_POOL_POP(p_pool, unit)
Definition: abti_log.h:30
#define LOG_DEBUG_POOL_REMOVE(p_pool, unit)
Definition: abti_log.h:29
#define ABTU_ret_err
Definition: abtu.h:49