Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
6797af1c248e28159940c0bf594fc27a3dfcb3be
[simgrid.git] / src / simix / xbt_context_private.h
1 /* a fast and simple context switching library                              */
2
3 /* Copyright (c) 2004-2008 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 _XBT_CONTEXT_PRIVATE_H
10 #define _XBT_CONTEXT_PRIVATE_H
11
12 #include "xbt/sysdep.h"
13 #include "simix/context.h"
14 #include "xbt/swag.h"
15
16 SG_BEGIN_DECL()
17
18 /* *********************** */
19 /* Context type definition */
20 /* *********************** */
21 /* the following function pointers types describe the interface that all context
22    concepts must implement */
23
24 typedef void (*xbt_pfn_context_free_t) (xbt_context_t);    /* function used to destroy the specified context */
25
26 typedef void (*xbt_pfn_context_kill_t) (xbt_context_t);    /* function used to kill the specified context */
27
28 typedef void (*xbt_pfn_context_schedule_t) (xbt_context_t);    /* function used to resume the specified context */
29
30 typedef void (*xbt_pfn_context_yield_t) (void);    /* function used to yield the specified context */
31
32 typedef void (*xbt_pfn_context_start_t) (xbt_context_t);   /* function used to start the specified context */
33
34 typedef void (*xbt_pfn_context_stop_t) (int);    /* function used to stop the current context */
35
36 /* each context type must contain this macro at its begining -- OOP in C :/ */
37 #define XBT_CTX_BASE_T \
38   s_xbt_swag_hookup_t hookup; \
39   char *name; \
40   void_f_pvoid_t cleanup_func; \
41   void *cleanup_arg; \
42   ex_ctx_t *exception; \
43   int iwannadie; \
44   xbt_main_func_t code; \
45   int argc; \
46   char **argv; \
47   void_f_pvoid_t startup_func; \
48   void *startup_arg; \
49   xbt_pfn_context_free_t free; \
50   xbt_pfn_context_kill_t kill; \
51   xbt_pfn_context_schedule_t schedule; \
52   xbt_pfn_context_yield_t yield; \
53   xbt_pfn_context_start_t start; \
54   xbt_pfn_context_stop_t stop
55
56 /* all other context types derive from this structure */
57 typedef struct s_xbt_context {
58   XBT_CTX_BASE_T;
59 } s_xbt_context_t;
60
61 /* ****************** */
62 /* Globals definition */
63 /* ****************** */
64
65 /* Important guys */
66 extern xbt_context_t current_context;
67 extern xbt_context_t maestro_context;
68
69 /* All dudes lists */
70 extern xbt_swag_t context_living;
71 extern xbt_swag_t context_to_destroy;
72
73 /* *********************** */
74 /* factory type definition */
75 /* *********************** */
76
77 typedef struct s_xbt_context_factory *xbt_context_factory_t;
78
79 /* The following function pointer types describe the interface that any context 
80    factory should implement */
81
82 /* function used to create a new context */
83 typedef xbt_context_t (*xbt_pfn_context_factory_create_context_t)
84   (const char *, xbt_main_func_t, void_f_pvoid_t, void *, void_f_pvoid_t, void *, int, char **);
85
86 /* function used to create the context for the maestro process */
87 typedef int (*xbt_pfn_context_factory_create_maestro_context_t) (xbt_context_t*);
88
89 /* this function finalize the specified context factory */
90 typedef int (*xbt_pfn_context_factory_finalize_t) (xbt_context_factory_t*);
91
92 /* interface of the context factories */
93 typedef struct s_xbt_context_factory {
94   xbt_pfn_context_factory_create_maestro_context_t create_maestro_context;
95   xbt_pfn_context_factory_create_context_t create_context;
96   xbt_pfn_context_factory_finalize_t finalize;
97   const char *name;
98 } s_xbt_context_factory_t;
99
100 /* Selects a context factory associated with the name specified by the parameter name.
101  * If successful the function returns 0. Otherwise the function returns the error code.
102  */
103 int xbt_context_select_factory(const char *name);
104
105 /* Initializes a context factory from the name specified by the parameter name.
106  * If the factory cannot be found, an exception is raised.
107  */
108 void xbt_context_init_factory_by_name(xbt_context_factory_t * factory, const char *name);
109
110 /* All factories init */
111 void xbt_ctx_thread_factory_init(xbt_context_factory_t * factory);
112
113 void xbt_ctx_sysv_factory_init(xbt_context_factory_t * factory);
114
115 void xbt_ctx_java_factory_init(xbt_context_factory_t * factory);
116
117 SG_END_DECL()
118 #endif /* !_XBT_CONTEXT_PRIVATE_H */