ARGOBOTS
abtd_context.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 ABTD_CONTEXT_H_INCLUDED
7 #define ABTD_CONTEXT_H_INCLUDED
8 
9 #include "abt_config.h"
10 
11 #ifndef ABT_CONFIG_USE_FCONTEXT
12 #define _XOPEN_SOURCE
13 #include <ucontext.h>
14 #endif
15 
16 typedef struct ABTD_thread_context ABTD_thread_context;
17 
18 typedef struct ABTD_thread_context_atomic_ptr {
19  ABTD_atomic_ptr val;
20 } ABTD_thread_context_atomic_ptr;
21 
22 static inline ABTD_thread_context *ABTD_atomic_relaxed_load_thread_context_ptr(
23  const ABTD_thread_context_atomic_ptr *ptr)
24 {
25  return (ABTD_thread_context *)ABTD_atomic_relaxed_load_ptr(&ptr->val);
26 }
27 
28 static inline ABTD_thread_context *ABTD_atomic_acquire_load_thread_context_ptr(
29  const ABTD_thread_context_atomic_ptr *ptr)
30 {
31  return (ABTD_thread_context *)ABTD_atomic_acquire_load_ptr(&ptr->val);
32 }
33 
34 static inline void ABTD_atomic_relaxed_store_thread_context_ptr(
35  ABTD_thread_context_atomic_ptr *ptr, ABTD_thread_context *p_ctx)
36 {
37  ABTD_atomic_relaxed_store_ptr(&ptr->val, (void *)p_ctx);
38 }
39 
40 static inline void ABTD_atomic_release_store_thread_context_ptr(
41  ABTD_thread_context_atomic_ptr *ptr, ABTD_thread_context *p_ctx)
42 {
43  ABTD_atomic_release_store_ptr(&ptr->val, (void *)p_ctx);
44 }
45 
46 struct ABTD_thread_context {
47  void *p_ctx; /* actual context of fcontext, or a
48  * pointer to uctx */
49  void (*f_thread)(void *); /* ULT function */
50  void *p_arg; /* ULT function argument */
51  ABTD_thread_context_atomic_ptr p_link; /* pointer to scheduler context */
52 #ifndef ABT_CONFIG_USE_FCONTEXT
53  ucontext_t uctx; /* ucontext entity pointed by p_ctx */
54  void (*f_uctx_thread)(void *); /* root function called by ucontext */
55  void *p_uctx_arg; /* argument for root function */
56 #endif
57 };
58 
59 static void ABTD_thread_context_make(ABTD_thread_context *p_ctx, void *sp,
60  size_t size, void (*thread_func)(void *));
61 static void ABTD_thread_context_jump(ABTD_thread_context *p_old,
62  ABTD_thread_context *p_new, void *arg);
63 static void ABTD_thread_context_take(ABTD_thread_context *p_old,
64  ABTD_thread_context *p_new, void *arg);
65 #if ABT_CONFIG_THREAD_TYPE == ABT_THREAD_TYPE_DYNAMIC_PROMOTION
66 static void ABTD_thread_context_init_and_call(ABTD_thread_context *p_ctx,
67  void *sp,
68  void (*thread_func)(void *),
69  void *arg);
70 #endif
71 
72 void ABTD_thread_print_context(ABTI_thread *p_thread, FILE *p_os, int indent);
73 
74 #ifdef ABT_CONFIG_USE_FCONTEXT
75 #include "abtd_fcontext.h"
76 #else
77 #include "abtd_ucontext.h"
78 #endif
79 
80 #endif /* ABTD_CONTEXT_H_INCLUDED */