ARGOBOTS  dce6e727ffc4ca5b3ffc04cb9517c6689be51ec5
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 void ABTI_sched_discard_and_free(ABTI_global *p_global,
44  ABTI_local *p_local,
45  ABTI_sched *p_sched,
46  ABT_bool force_free)
47 {
48  p_sched->used = ABTI_SCHED_NOT_USED;
49  if (p_sched->automatic == ABT_TRUE || force_free) {
50  ABTI_sched_free(p_global, p_local, p_sched, force_free);
51  } else {
52  /* Threads should be discarded here. */
53  if (p_sched->p_ythread) {
54  ABTI_thread_free(p_global, p_local, &p_sched->p_ythread->thread);
55  p_sched->p_ythread = NULL;
56  }
57  }
58 }
59 
60 static inline void ABTI_sched_set_request(ABTI_sched *p_sched, uint32_t req)
61 {
62  ABTD_atomic_fetch_or_uint32(&p_sched->request, req);
63 }
64 
65 static inline void ABTI_sched_unset_request(ABTI_sched *p_sched, uint32_t req)
66 {
67  ABTD_atomic_fetch_and_uint32(&p_sched->request, ~req);
68 }
69 
70 #ifdef ABT_CONFIG_USE_SCHED_SLEEP
71 #define CNT_DECL(c) int c
72 #define CNT_INIT(c, v) c = v
73 #define CNT_INC(c) c++
74 #define SCHED_SLEEP(c, t) \
75  if (c == 0) \
76  nanosleep(&(t), NULL)
77 #else
78 #define CNT_DECL(c)
79 #define CNT_INIT(c, v)
80 #define CNT_INC(c)
81 #define SCHED_SLEEP(c, t)
82 #endif
83 
84 #endif /* ABTI_SCHED_H_INCLUDED */
ABT_bool
int ABT_bool
Boolean type.
Definition: abt.h:1043
ABT_sched
struct ABT_sched_opaque * ABT_sched
Scheduler handle type.
Definition: abt.h:845
ABT_TRUE
#define ABT_TRUE
True constant for ABT_bool.
Definition: abt.h:784
ABT_SCHED_NULL
#define ABT_SCHED_NULL
Definition: abt.h:1100