ARGOBOTS  1227c643f7a7f974f1f1778a9ffebd29d7dafecf
 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 #define _XOPEN_SOURCE
13 #include <ucontext.h>
14 #endif
15 
16 typedef struct ABTD_ythread_context ABTD_ythread_context;
17 
18 typedef struct ABTD_ythread_context_atomic_ptr {
19  ABTD_atomic_ptr val;
20 } ABTD_ythread_context_atomic_ptr;
21 
22 static inline ABTD_ythread_context *
23 ABTD_atomic_relaxed_load_ythread_context_ptr(
24  const ABTD_ythread_context_atomic_ptr *ptr)
25 {
26  return (ABTD_ythread_context *)ABTD_atomic_relaxed_load_ptr(&ptr->val);
27 }
28 
29 static inline ABTD_ythread_context *
30 ABTD_atomic_acquire_load_ythread_context_ptr(
31  const ABTD_ythread_context_atomic_ptr *ptr)
32 {
33  return (ABTD_ythread_context *)ABTD_atomic_acquire_load_ptr(&ptr->val);
34 }
35 
36 static inline void ABTD_atomic_relaxed_store_ythread_context_ptr(
37  ABTD_ythread_context_atomic_ptr *ptr, ABTD_ythread_context *p_ctx)
38 {
39  ABTD_atomic_relaxed_store_ptr(&ptr->val, (void *)p_ctx);
40 }
41 
42 static inline void ABTD_atomic_release_store_ythread_context_ptr(
43  ABTD_ythread_context_atomic_ptr *ptr, ABTD_ythread_context *p_ctx)
44 {
45  ABTD_atomic_release_store_ptr(&ptr->val, (void *)p_ctx);
46 }
47 
48 struct ABTD_ythread_context {
49  void *p_ctx; /* actual context of fcontext, or a
50  * pointer to uctx */
51  ABTD_ythread_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_ythread_context_make(ABTD_ythread_context *p_ctx, void *sp,
60  size_t size, void (*thread_func)(void *));
61 static void ABTD_ythread_context_jump(ABTD_ythread_context *p_old,
62  ABTD_ythread_context *p_new, void *arg);
63 ABTU_noreturn static void ABTD_ythread_context_take(ABTD_ythread_context *p_old,
64  ABTD_ythread_context *p_new,
65  void *arg);
66 #if ABT_CONFIG_THREAD_TYPE == ABT_THREAD_TYPE_DYNAMIC_PROMOTION
67 static void ABTD_ythread_context_init_and_call(ABTD_ythread_context *p_ctx,
68  void *sp,
69  void (*thread_func)(void *),
70  void *arg);
71 #endif
72 
73 void ABTD_ythread_print_context(ABTI_ythread *p_ythread, FILE *p_os,
74  int indent);
75 
76 #ifdef ABT_CONFIG_USE_FCONTEXT
77 #include "abtd_fcontext.h"
78 #else
79 #include "abtd_ucontext.h"
80 #endif
81 
82 #endif /* ABTD_CONTEXT_H_INCLUDED */
#define ABTU_noreturn
Definition: abtu.h:31