Logo AND Algorithmique Numérique Distribuée

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