ARGOBOTS  4dc37e16e1b227a480715ab67dae1dcfb4d2d4e0
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 
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 
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 */
ABTI_sched_get_ptr
static ABTI_sched * ABTI_sched_get_ptr(ABT_sched sched)
Definition: abti_sched.h:11
ABT_bool
int ABT_bool
Boolean type.
Definition: abt.h:1043
ABTI_SCHED_NOT_USED
@ ABTI_SCHED_NOT_USED
Definition: abti.h:71
ABTI_sched::automatic
ABT_bool automatic
Definition: abti.h:321
ABTI_sched_get_handle
static ABT_sched ABTI_sched_get_handle(ABTI_sched *p_sched)
Definition: abti_sched.h:26
ABTI_thread_free
void ABTI_thread_free(ABTI_global *p_global, ABTI_local *p_local, ABTI_thread *p_thread)
Definition: thread.c:2616
ABTI_sched::p_ythread
ABTI_ythread * p_ythread
Definition: abti.h:330
ABTI_sched::used
ABTI_sched_used used
Definition: abti.h:320
ABT_sched
struct ABT_sched_opaque * ABT_sched
Scheduler handle type.
Definition: abt.h:845
ABTI_sched_discard_and_free
static void ABTI_sched_discard_and_free(ABTI_global *p_global, ABTI_local *p_local, ABTI_sched *p_sched, ABT_bool force_free)
Definition: abti_sched.h:43
ABTI_sched_unset_request
static void ABTI_sched_unset_request(ABTI_sched *p_sched, uint32_t req)
Definition: abti_sched.h:65
ABTI_sched_set_request
static void ABTI_sched_set_request(ABTI_sched *p_sched, uint32_t req)
Definition: abti_sched.h:60
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
ABTI_sched::request
ABTD_atomic_uint32 request
Definition: abti.h:327
ABTI_sched
Definition: abti.h:319
ABTD_atomic_fetch_and_uint32
static uint32_t ABTD_atomic_fetch_and_uint32(ABTD_atomic_uint32 *ptr, uint32_t v)
Definition: abtd_atomic.h:573
ABTD_atomic_fetch_or_uint32
static uint32_t ABTD_atomic_fetch_or_uint32(ABTD_atomic_uint32 *ptr, uint32_t v)
Definition: abtd_atomic.h:631
ABTI_sched_free
void ABTI_sched_free(ABTI_global *p_global, ABTI_local *p_local, ABTI_sched *p_sched, ABT_bool force_free)
Definition: sched.c:889
ABTI_ythread::thread
ABTI_thread thread
Definition: abti.h:457
ABTI_local
struct ABTI_local ABTI_local
Definition: abti.h:132
ABTI_global
Definition: abti.h:223