Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
bc7a147e6dd80e71fa803d1775ae4f80a892d39c
[simgrid.git] / src / simix / smx_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/private.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 /* each context type must contain this macro at its begining -- OOP in C :/ */
25 #define SMX_CTX_BASE_T \
26   s_xbt_swag_hookup_t hookup; \
27   ex_ctx_t *exception; \
28   xbt_main_func_t code; \
29
30 /* all other context types derive from this structure */
31 typedef struct s_smx_context {
32   SMX_CTX_BASE_T;
33 } s_smx_context_t;
34
35 /* *********************** */
36 /* factory type definition */
37 /* *********************** */
38
39 /* The following function pointer types describe the interface that any context 
40    factory should implement */
41
42 /* function used to create a new context */
43 typedef int (*smx_pfn_context_factory_create_context_t) (smx_process_t *, xbt_main_func_t);
44
45 /* function used to create the context for the maestro process */
46 typedef int (*smx_pfn_context_factory_create_maestro_context_t) (smx_process_t*);
47
48 /* this function finalize the specified context factory */
49 typedef int (*smx_pfn_context_factory_finalize_t) (smx_context_factory_t*);
50
51 /* function used to destroy the specified context */
52 typedef void (*smx_pfn_context_free_t) (smx_process_t);
53
54 /* function used to kill the specified context */
55 typedef void (*smx_pfn_context_kill_t) (smx_process_t);
56
57 /* function used to resume the specified context */
58 typedef void (*smx_pfn_context_schedule_t) (smx_process_t);
59
60 /* function used to yield the specified context */
61 typedef void (*smx_pfn_context_yield_t) (void);
62
63 /* function used to start the specified context */
64 typedef void (*smx_pfn_context_start_t) (smx_process_t);
65
66 /* function used to stop the current context */
67 typedef void (*smx_pfn_context_stop_t) (int);
68
69 /* interface of the context factories */
70 typedef struct s_smx_context_factory {
71   smx_pfn_context_factory_create_maestro_context_t create_maestro_context;
72   smx_pfn_context_factory_create_context_t create_context;
73   smx_pfn_context_factory_finalize_t finalize;
74   smx_pfn_context_free_t free;
75   smx_pfn_context_kill_t kill;
76   smx_pfn_context_schedule_t schedule;
77   smx_pfn_context_yield_t yield;
78   smx_pfn_context_start_t start;
79   smx_pfn_context_stop_t stop;
80   const char *name;
81 } s_smx_context_factory_t;
82
83 /* Selects a context factory associated with the name specified by the parameter name.
84  * If successful the function returns 0. Otherwise the function returns the error code.
85  */
86 int SIMIX_context_select_factory(const char *name);
87
88 /* Initializes a context factory from the name specified by the parameter name.
89  * If the factory cannot be found, an exception is raised.
90  */
91 void SIMIX_context_init_factory_by_name(smx_context_factory_t * factory, const char *name);
92
93 /* All factories init */
94 void SIMIX_ctx_thread_factory_init(smx_context_factory_t * factory);
95
96 void SIMIX_ctx_sysv_factory_init(smx_context_factory_t * factory);
97
98 void SIMIX_ctx_java_factory_init(smx_context_factory_t * factory);
99
100 SG_END_DECL()
101 #endif /* !_XBT_CONTEXT_PRIVATE_H */