ARGOBOTS
abti_sched.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_SCHED_H_INCLUDED
7 #define ABTI_SCHED_H_INCLUDED
8 
9 /* Inlined functions for Scheduler */
10 
11 static inline ABTI_sched *ABTI_sched_get_ptr(ABT_sched sched)
12 {
13 #ifndef ABT_CONFIG_DISABLE_ERROR_CHECK
14  ABTI_sched *p_sched;
15  if (sched == ABT_SCHED_NULL) {
16  p_sched = NULL;
17  } else {
18  p_sched = (ABTI_sched *)sched;
19  }
20  return p_sched;
21 #else
22  return (ABTI_sched *)sched;
23 #endif
24 }
25 
26 static inline ABT_sched ABTI_sched_get_handle(ABTI_sched *p_sched)
27 {
28 #ifndef ABT_CONFIG_DISABLE_ERROR_CHECK
29  ABT_sched h_sched;
30  if (p_sched == NULL) {
31  h_sched = ABT_SCHED_NULL;
32  } else {
33  h_sched = (ABT_sched)p_sched;
34  }
35  return h_sched;
36 #else
37  return (ABT_sched)p_sched;
38 #endif
39 }
40 
41 /* Set `used` of p_sched to NOT_USED and free p_sched if its `automatic` is
42  * ABT_TRUE, which means it is safe to free p_sched inside the runtime. */
43 static inline int ABTI_sched_discard_and_free(ABTI_local *p_local,
44  ABTI_sched *p_sched)
45 {
46  int abt_errno = ABT_SUCCESS;
47  p_sched->used = ABTI_SCHED_NOT_USED;
48  if (p_sched->automatic == ABT_TRUE) {
49  abt_errno = ABTI_sched_free(p_local, p_sched);
50  }
51  return abt_errno;
52 }
53 
54 static inline void ABTI_sched_set_request(ABTI_sched *p_sched, uint32_t req)
55 {
56  ABTD_atomic_fetch_or_uint32(&p_sched->request, req);
57 }
58 
59 static inline void ABTI_sched_unset_request(ABTI_sched *p_sched, uint32_t req)
60 {
61  ABTD_atomic_fetch_and_uint32(&p_sched->request, ~req);
62 }
63 
64 static inline ABT_bool ABTI_sched_has_unit(ABTI_sched *p_sched)
65 {
66  int p;
67  size_t s;
68 
69  for (p = 0; p < p_sched->num_pools; p++) {
70  ABT_pool pool = p_sched->pools[p];
71  ABTI_pool *p_pool = ABTI_pool_get_ptr(pool);
72  s = ABTI_pool_get_size(p_pool);
73  if (s > 0)
74  return ABT_TRUE;
75  }
76 
77  return ABT_FALSE;
78 }
79 
80 #ifdef ABT_CONFIG_USE_SCHED_SLEEP
81 #define CNT_DECL(c) int c
82 #define CNT_INIT(c, v) c = v
83 #define CNT_INC(c) c++
84 #define SCHED_SLEEP(c, t) \
85  if (c == 0) \
86  nanosleep(&(t), NULL)
87 #else
88 #define CNT_DECL(c)
89 #define CNT_INIT(c, v)
90 #define CNT_INC(c)
91 #define SCHED_SLEEP(c, t)
92 #endif
93 
94 #endif /* ABTI_SCHED_H_INCLUDED */
struct ABT_sched_opaque * ABT_sched
Definition: abt.h:257
int ABT_bool
Definition: abt.h:309
struct ABT_pool_opaque * ABT_pool
Definition: abt.h:267
#define ABT_FALSE
Definition: abt.h:224
#define ABT_SUCCESS
Definition: abt.h:64
#define ABT_TRUE
Definition: abt.h:223
#define ABT_SCHED_NULL
Definition: abt.h:339