ARGOBOTS  23067fa015f4b179569e2d52278c1072e674eb1e
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Groups
abti_unit.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_UNIT_H_INCLUDED
7 #define ABTI_UNIT_H_INCLUDED
8 
9 /* Inlined functions for ABTI_unit */
10 
11 static inline void ABTI_ktable_set(ABTI_xstream *p_local_xstream,
12  ABTD_atomic_ptr *pp_ktable, ABTI_key *p_key,
13  void *value);
14 static inline void *ABTI_ktable_get(ABTD_atomic_ptr *pp_ktable,
15  ABTI_key *p_key);
16 static inline int ABTI_ktable_is_valid(ABTI_ktable *p_ktable);
17 
18 static inline ABT_thread_state
19 ABTI_unit_state_get_thread_state(ABTI_unit_state state)
20 {
21  switch (state) {
22  case ABTI_UNIT_STATE_READY:
24  case ABTI_UNIT_STATE_RUNNING:
26  case ABTI_UNIT_STATE_BLOCKED:
28  case ABTI_UNIT_STATE_TERMINATED:
30  default:
31  ABTI_ASSERT(0);
33  }
34 }
35 
36 static inline ABT_task_state
37 ABTI_unit_state_get_task_state(ABTI_unit_state state)
38 {
39  switch (state) {
40  case ABTI_UNIT_STATE_READY:
41  return ABT_TASK_STATE_READY;
42  case ABTI_UNIT_STATE_RUNNING:
44  case ABTI_UNIT_STATE_TERMINATED:
46  case ABTI_UNIT_STATE_BLOCKED:
47  default:
48  ABTI_ASSERT(0);
50  }
51 }
52 
53 static inline ABT_bool ABTI_unit_type_is_thread(ABTI_unit_type type)
54 {
55  return (type & ABTI_UNIT_TYPE_THREAD) ? ABT_TRUE : ABT_FALSE;
56 }
57 
58 static inline ABT_bool ABTI_unit_type_is_task(ABTI_unit_type type)
59 {
60  return (!(type & (ABTI_UNIT_TYPE_THREAD | ABTI_UNIT_TYPE_EXT))) ? ABT_TRUE
61  : ABT_FALSE;
62 }
63 
64 static inline ABT_bool ABTI_unit_type_is_ext(ABTI_unit_type type)
65 {
66  return (type & ABTI_UNIT_TYPE_EXT) ? ABT_TRUE : ABT_FALSE;
67 }
68 
69 static inline ABT_bool ABTI_unit_type_is_thread_user(ABTI_unit_type type)
70 {
71  return (type & ABTI_UNIT_TYPE_THREAD_TYPE_USER) ? ABT_TRUE : ABT_FALSE;
72 }
73 
74 static inline ABT_bool ABTI_unit_type_is_thread_main(ABTI_unit_type type)
75 {
76  return (type & ABTI_UNIT_TYPE_THREAD_TYPE_MAIN) ? ABT_TRUE : ABT_FALSE;
77 }
78 
79 static inline ABT_bool ABTI_unit_type_is_thread_main_sched(ABTI_unit_type type)
80 {
81  return (type & ABTI_UNIT_TYPE_THREAD_TYPE_MAIN_SCHED) ? ABT_TRUE
82  : ABT_FALSE;
83 }
84 
85 static inline ABT_unit_type ABTI_unit_type_get_type(ABTI_unit_type type)
86 {
87  if (ABTI_unit_type_is_thread(type)) {
88  return ABT_UNIT_TYPE_THREAD;
89  } else if (ABTI_unit_type_is_task(type)) {
90  return ABT_UNIT_TYPE_TASK;
91  } else {
92  ABTI_ASSERT(ABTI_unit_type_is_ext(type));
93  return ABT_UNIT_TYPE_EXT;
94  }
95 }
96 
97 static inline ABTI_thread *ABTI_unit_get_thread(ABTI_unit *p_unit)
98 {
99  return (ABTI_thread *)(((char *)p_unit) - offsetof(ABTI_thread, unit_def));
100 }
101 
102 static inline ABTI_task *ABTI_unit_get_task(ABTI_unit *p_unit)
103 {
104  return (ABTI_task *)(((char *)p_unit) - offsetof(ABTI_task, unit_def));
105 }
106 
107 #endif /* ABTI_UNIT_H_INCLUDED */
#define ABTU_unreachable()
Definition: abtu.h:25
int ABT_bool
Definition: abt.h:375
#define ABT_FALSE
Definition: abt.h:287
ABT_task_state
Definition: abt.h:132
#define ABT_TRUE
Definition: abt.h:286
ABT_unit_type
Definition: abt.h:171
ABT_thread_state
Definition: abt.h:125