ARGOBOTS
abti_self.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_SELF_H_INCLUDED
7 #define ABTI_SELF_H_INCLUDED
8 
9 static inline ABTI_native_thread_id
10 ABTI_self_get_native_thread_id(ABTI_local *p_local)
11 {
12 #ifndef ABT_CONFIG_DISABLE_EXT_THREAD
13  /* This is when an external thread called this routine. */
14  if (p_local == NULL) {
15  /* A pointer to a thread local variable can distinguish all external
16  * threads and execution streams. */
17  return (ABTI_native_thread_id)ABTI_local_get_local_ptr();
18  }
19 #endif
20  return (ABTI_native_thread_id)p_local->p_xstream;
21 }
22 
23 static inline ABTI_unit_id ABTI_self_get_unit_id(ABTI_local *p_local)
24 {
25 #ifndef ABT_CONFIG_DISABLE_EXT_THREAD
26  /* This is when an external thread called this routine. */
27  if (p_local == NULL) {
28  /* A pointer to a thread local variable is unique to an external thread
29  * and its value is different from pointers to ULTs and tasks. */
30  return (ABTI_unit_id)ABTI_local_get_local_ptr();
31  }
32 #endif
33  ABTI_unit_id id;
34  if (p_local->p_thread) {
35  id = (ABTI_unit_id)p_local->p_thread;
36  } else if (p_local->p_task) {
37  id = (ABTI_unit_id)p_local->p_task;
38  } else {
39  /* should not reach here */
40  id = 0;
41  ABTI_ASSERT(0);
42  }
43  return id;
44 }
45 
46 static inline ABT_unit_type ABTI_self_get_type(ABTI_local *p_local)
47 {
48  ABTI_ASSERT(gp_ABTI_global);
49 
50 #ifndef ABT_CONFIG_DISABLE_EXT_THREAD
51  /* This is when an external thread called this routine. */
52  if (p_local == NULL) {
53  return ABT_UNIT_TYPE_EXT;
54  }
55 #endif
56 
57  if (p_local->p_task != NULL) {
58  return ABT_UNIT_TYPE_TASK;
59  } else {
60  /* Since p_local->p_thread can return NULL during executing
61  * ABTI_init(), it should always be safe to say that the type of caller
62  * is ULT if the control reaches here. */
63  return ABT_UNIT_TYPE_THREAD;
64  }
65 }
66 
67 #endif /* ABTI_SELF_H_INCLUDED */
ABTI_global * gp_ABTI_global
Definition: global.c:14
ABT_unit_type
Definition: abt.h:170