ARGOBOTS  29b0d4cc91ca184a8278ddf690fd0bcb2119000e
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Groups
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 #ifndef _XOPEN_SOURCE
13 #define _XOPEN_SOURCE
14 #endif
15 #include <ucontext.h>
16 #endif
17 
18 typedef struct ABTD_ythread_context ABTD_ythread_context;
19 
20 typedef struct ABTD_ythread_context_atomic_ptr {
21  ABTD_atomic_ptr val;
22 } ABTD_ythread_context_atomic_ptr;
23 
24 static inline ABTD_ythread_context *
25 ABTD_atomic_relaxed_load_ythread_context_ptr(
26  const ABTD_ythread_context_atomic_ptr *ptr)
27 {
28  return (ABTD_ythread_context *)ABTD_atomic_relaxed_load_ptr(&ptr->val);
29 }
30 
31 static inline ABTD_ythread_context *
32 ABTD_atomic_acquire_load_ythread_context_ptr(
33  const ABTD_ythread_context_atomic_ptr *ptr)
34 {
35  return (ABTD_ythread_context *)ABTD_atomic_acquire_load_ptr(&ptr->val);
36 }
37 
38 static inline void ABTD_atomic_relaxed_store_ythread_context_ptr(
39  ABTD_ythread_context_atomic_ptr *ptr, ABTD_ythread_context *p_ctx)
40 {
41  ABTD_atomic_relaxed_store_ptr(&ptr->val, (void *)p_ctx);
42 }
43 
44 static inline void ABTD_atomic_release_store_ythread_context_ptr(
45  ABTD_ythread_context_atomic_ptr *ptr, ABTD_ythread_context *p_ctx)
46 {
47  ABTD_atomic_release_store_ptr(&ptr->val, (void *)p_ctx);
48 }
49 
50 struct ABTD_ythread_context {
51  void *p_ctx; /* actual context of fcontext, or a
52  * pointer to uctx */
53  ABTD_ythread_context_atomic_ptr p_link; /* pointer to scheduler context */
54 #ifndef ABT_CONFIG_USE_FCONTEXT
55  ucontext_t uctx; /* ucontext entity pointed by p_ctx */
56  void (*f_uctx_thread)(void *); /* root function called by ucontext */
57  void *p_uctx_arg; /* argument for root function */
58 #endif
59 };
60 
61 static void ABTD_ythread_context_make(ABTD_ythread_context *p_ctx, void *sp,
62  size_t size, void (*thread_func)(void *));
63 static void ABTD_ythread_context_jump(ABTD_ythread_context *p_old,
64  ABTD_ythread_context *p_new, void *arg);
65 ABTU_noreturn static void ABTD_ythread_context_take(ABTD_ythread_context *p_old,
66  ABTD_ythread_context *p_new,
67  void *arg);
68 #if ABT_CONFIG_THREAD_TYPE == ABT_THREAD_TYPE_DYNAMIC_PROMOTION
69 static void ABTD_ythread_context_init_and_call(ABTD_ythread_context *p_ctx,
70  void *sp,
71  void (*thread_func)(void *),
72  void *arg);
73 #endif
74 
75 void ABTD_ythread_print_context(ABTI_ythread *p_ythread, FILE *p_os,
76  int indent);
77 
78 #ifdef ABT_CONFIG_USE_FCONTEXT
79 #include "abtd_fcontext.h"
80 #else
81 #include "abtd_ucontext.h"
82 #endif
83 
84 #endif /* ABTD_CONTEXT_H_INCLUDED */
#define ABTU_noreturn
Definition: abtu.h:31