1 /* a fast and simple context switching library */
3 /* Copyright (c) 2004-2008 the SimGrid team. */
4 /* All rights reserved. */
6 /* This program is free software; you can redistribute it and/or modify it
7 * under the terms of the license (GNU LGPL) which comes with this package. */
9 #ifndef _XBT_CONTEXT_PRIVATE_H
10 #define _XBT_CONTEXT_PRIVATE_H
13 #include "simix/private.h"
17 /* *********************** */
18 /* Context type definition */
19 /* *********************** */
20 /* the following function pointers types describe the interface that all context
21 concepts must implement */
22 /* the following function pointers types describe the interface that all context
23 concepts must implement */
25 /* each context type derive from this structure, so they must contain this structure
26 * at their begining -- OOP in C :/ */
27 typedef struct s_smx_context {
28 s_xbt_swag_hookup_t hookup;
32 void_f_pvoid_t cleanup_func;
35 /* methods of this class */
36 void smx_ctx_base_factory_init(smx_context_factory_t * factory);
37 int smx_ctx_base_factory_finalize(smx_context_factory_t * factory);
40 smx_ctx_base_factory_create_context_sized(size_t size,
41 xbt_main_func_t code, int argc, char** argv,
42 void_f_pvoid_t cleanup_func, void* cleanup_arg);
43 void smx_ctx_base_free(smx_context_t context);
44 void smx_ctx_base_stop(smx_context_t context);
46 /* Functions of sysv context mecanism: lua inherites them */
48 #ifdef CONTEXT_UCONTEXT
50 /* lower this if you want to reduce the memory consumption */
51 #ifndef CONTEXT_STACK_SIZE /* allow lua to override this */
52 #define CONTEXT_STACK_SIZE 128*1024
53 #endif /*CONTEXT_STACK_SIZE */
55 #include "context_sysv_config.h" /* loads context system definitions */
56 #include <ucontext.h> /* context relative declarations */
58 typedef struct s_smx_ctx_sysv {
59 s_smx_ctx_base_t super; /* Fields of super implementation */
60 ucontext_t uc; /* the thread that execute the code */
61 char stack[CONTEXT_STACK_SIZE]; /* the thread stack size */
62 #ifdef HAVE_VALGRIND_VALGRIND_H
63 unsigned int valgrind_stack_id; /* the valgrind stack id */
65 } s_smx_ctx_sysv_t, *smx_ctx_sysv_t;smx_context_t
66 smx_ctx_sysv_create_context_sized(size_t size,
67 xbt_main_func_t code, int argc, char** argv,
68 void_f_pvoid_t cleanup_func, void* cleanup_arg);
69 void smx_ctx_sysv_free(smx_context_t context);
70 void smx_ctx_sysv_stop(smx_context_t context);
71 void smx_ctx_sysv_suspend(smx_context_t context);
72 void smx_ctx_sysv_resume(smx_context_t new_context);
76 #endif /* !_XBT_CONTEXT_PRIVATE_H */