Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Add a flag --cfg=contexts/stacksize and rename other context flags to be
[simgrid.git] / include / simix / context.h
1 /* a fast and simple context switching library                              */
2
3 /* Copyright (c) 2009, 2010. The SimGrid Team.
4  * All rights reserved.                                                     */
5
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. */
8
9 #ifndef _SIMIX_CONTEXT_H
10 #define _SIMIX_CONTEXT_H
11
12 #include "xbt/swag.h"
13 #include "simix/datatypes.h"
14
15 SG_BEGIN_DECL()
16 /******************************** Context *************************************/
17 typedef struct s_smx_context *smx_context_t;
18 typedef struct s_smx_context_factory *smx_context_factory_t;
19
20 /* Process creation/destruction callbacks */
21 typedef void (*void_pfn_smxprocess_t) (smx_process_t);
22
23
24 /* The following function pointer types describe the interface that any context
25    factory should implement */
26
27
28 typedef smx_context_t(*smx_pfn_context_factory_create_context_t)
29   (xbt_main_func_t, int, char **, void_pfn_smxprocess_t, void* data);
30 typedef int (*smx_pfn_context_factory_finalize_t) (smx_context_factory_t*);
31 typedef void (*smx_pfn_context_free_t) (smx_context_t);
32 typedef void (*smx_pfn_context_start_t) (smx_context_t);
33 typedef void (*smx_pfn_context_stop_t) (smx_context_t);
34 typedef void (*smx_pfn_context_suspend_t) (smx_context_t context);
35 typedef void (*smx_pfn_context_runall_t) (xbt_dynar_t processes);
36 typedef smx_context_t (*smx_pfn_context_self_t) (void);
37 typedef void* (*smx_pfn_context_get_data_t) (smx_context_t context);
38
39 /* interface of the context factories */
40 typedef struct s_smx_context_factory {
41   const char *name;
42   smx_pfn_context_factory_create_context_t create_context;
43   smx_pfn_context_factory_finalize_t finalize;
44   smx_pfn_context_free_t free;
45   smx_pfn_context_stop_t stop;
46   smx_pfn_context_suspend_t suspend;
47   smx_pfn_context_runall_t runall;
48   smx_pfn_context_self_t self;
49   smx_pfn_context_get_data_t get_data;
50 } s_smx_context_factory_t;
51
52
53
54 /* Hack: let msg load directly the right factory */
55 typedef void (*smx_ctx_factory_initializer_t)(smx_context_factory_t*);
56 extern smx_ctx_factory_initializer_t smx_factory_initializer_to_use;
57 extern char* smx_context_factory_name;
58 extern int smx_context_stack_size;
59 extern int smx_parallel_contexts;
60 extern smx_context_t smx_current_context;
61
62 /* *********************** */
63 /* Context type definition */
64 /* *********************** */
65 /* the following function pointers types describe the interface that all context
66    concepts must implement */
67 /* each context type derive from this structure, so they must contain this structure
68  * at their begining -- OOP in C :/ */
69 typedef struct s_smx_context {
70   s_xbt_swag_hookup_t hookup;
71   xbt_main_func_t code;
72   int argc;
73   char **argv;
74   void_pfn_smxprocess_t cleanup_func;
75   int iwannadie:1;
76   void *data;   /* Here SIMIX stores the smx_process_t containing the context */
77 } s_smx_ctx_base_t;
78
79 /* methods of this class */
80 void smx_ctx_base_factory_init(smx_context_factory_t *factory);
81 int smx_ctx_base_factory_finalize(smx_context_factory_t *factory);
82
83 smx_context_t
84 smx_ctx_base_factory_create_context_sized(size_t size,
85                                           xbt_main_func_t code, int argc,
86                                           char **argv,
87                                           void_pfn_smxprocess_t cleanup,
88                                           void* data);
89 void smx_ctx_base_free(smx_context_t context);
90 void smx_ctx_base_stop(smx_context_t context);
91 smx_context_t smx_ctx_base_self(void);
92 void *smx_ctx_base_get_data(smx_context_t context);
93
94 SG_END_DECL()
95
96 #endif                          /* !_XBT_CONTEXT_H */