Logo AND Algorithmique Numérique Distribuée

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