ARGOBOTS  66b1c39742507d8df30e8d28c54839b961a14814
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Groups
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_local *p_local,
44  ABTI_sched *p_sched,
45  ABT_bool force_free)
46 {
47  p_sched->used = ABTI_SCHED_NOT_USED;
48  if (p_sched->automatic == ABT_TRUE || force_free) {
49  ABTI_sched_free(p_local, p_sched, force_free);
50  } else {
51  /* Threads should be discarded here. */
52  ABTI_thread_free(p_local, &p_sched->p_ythread->thread);
53  p_sched->p_ythread = NULL;
54  }
55 }
56 
57 static inline void ABTI_sched_set_request(ABTI_sched *p_sched, uint32_t req)
58 {
59  ABTD_atomic_fetch_or_uint32(&p_sched->request, req);
60 }
61 
62 static inline void ABTI_sched_unset_request(ABTI_sched *p_sched, uint32_t req)
63 {
64  ABTD_atomic_fetch_and_uint32(&p_sched->request, ~req);
65 }
66 
67 #ifdef ABT_CONFIG_USE_SCHED_SLEEP
68 #define CNT_DECL(c) int c
69 #define CNT_INIT(c, v) c = v
70 #define CNT_INC(c) c++
71 #define SCHED_SLEEP(c, t) \
72  if (c == 0) \
73  nanosleep(&(t), NULL)
74 #else
75 #define CNT_DECL(c)
76 #define CNT_INIT(c, v)
77 #define CNT_INC(c)
78 #define SCHED_SLEEP(c, t)
79 #endif
80 
81 #endif /* ABTI_SCHED_H_INCLUDED */
static void ABTI_sched_discard_and_free(ABTI_local *p_local, ABTI_sched *p_sched, ABT_bool force_free)
Definition: abti_sched.h:43
ABTI_ythread * p_ythread
Definition: abti.h:267
struct ABT_sched_opaque * ABT_sched
Definition: abt.h:319
static ABT_sched ABTI_sched_get_handle(ABTI_sched *p_sched)
Definition: abti_sched.h:26
struct ABTI_local ABTI_local
Definition: abti.h:101
int ABT_bool
Definition: abt.h:373
static uint32_t ABTD_atomic_fetch_or_uint32(ABTD_atomic_uint32 *ptr, uint32_t v)
Definition: abtd_atomic.h:538
static uint32_t ABTD_atomic_fetch_and_uint32(ABTD_atomic_uint32 *ptr, uint32_t v)
Definition: abtd_atomic.h:489
void ABTI_sched_free(ABTI_local *p_local, ABTI_sched *p_sched, ABT_bool force_free)
Definition: sched.c:497
ABTD_atomic_uint32 request
Definition: abti.h:264
ABT_bool automatic
Definition: abti.h:261
static void ABTI_sched_unset_request(ABTI_sched *p_sched, uint32_t req)
Definition: abti_sched.h:62
ABTI_thread thread
Definition: abti.h:348
#define ABT_TRUE
Definition: abt.h:284
#define ABT_SCHED_NULL
Definition: abt.h:411
void ABTI_thread_free(ABTI_local *p_local, ABTI_thread *p_thread)
Definition: thread.c:1475
static ABTI_sched * ABTI_sched_get_ptr(ABT_sched sched)
Definition: abti_sched.h:11
static void ABTI_sched_set_request(ABTI_sched *p_sched, uint32_t req)
Definition: abti_sched.h:57
ABTI_sched_used used
Definition: abti.h:260