Logo AND Algorithmique Numérique Distribuée

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