Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
... untested ...
[simgrid.git] / src / simix / private.h
1 /*      $Id$     */
2
3 /* Copyright (c) 2007 Arnaud Legrand, Bruno Donnassolo.
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 SIMIX_PRIVATE_H
10 #define SIMIX_PRIVATE_H
11
12 #include <stdio.h>
13 #include "simix/simix.h"
14 #include "surf/surf.h"
15 #include "xbt/fifo.h"
16 #include "xbt/swag.h"
17 #include "xbt/dict.h"
18 #include "xbt/function_types.h"
19
20 /******************************** Datatypes ***********************************/
21
22
23 /*********************************** Host *************************************/
24
25 /** @brief Host datatype
26     @ingroup m_datatypes_management_details */
27 typedef struct s_smx_host {
28   char *name;              /**< @brief host name if any */
29   void *host;              /* SURF modeling */
30   xbt_swag_t process_list;
31   void *data;              /**< @brief user data */
32 } s_smx_host_t;
33
34 /********************************** Simix Global ******************************/
35
36 typedef struct s_smx_context_factory *smx_context_factory_t;
37
38 typedef struct SIMIX_Global {
39   smx_context_factory_t context_factory;
40   xbt_dict_t host;
41   xbt_swag_t process_to_run;
42   xbt_swag_t process_list;
43   xbt_swag_t process_to_destroy;
44   smx_process_t current_process;
45   smx_process_t maestro_process;
46   xbt_dict_t registered_functions;
47   smx_creation_func_t create_process_function;
48   void_f_pvoid_t kill_process_function;
49   void_f_pvoid_t cleanup_process_function;
50 } s_SIMIX_Global_t, *SIMIX_Global_t;
51
52 extern SIMIX_Global_t simix_global;
53
54 /******************************** Process *************************************/
55
56 typedef struct s_smx_context *smx_context_t;
57
58 /** @brief Process datatype
59     @ingroup m_datatypes_management_details @{ */
60      typedef struct s_smx_process {
61        s_xbt_swag_hookup_t process_hookup;
62        s_xbt_swag_hookup_t synchro_hookup;
63        s_xbt_swag_hookup_t host_proc_hookup;
64        s_xbt_swag_hookup_t destroy_hookup;
65
66        char *name;              /**< @brief process name if any */
67        smx_host_t smx_host;     /* the host on which the process is running */
68        smx_context_t context;   /* the context that executes the scheduler function */
69        int argc;                /* arguments number if any */
70        char **argv;             /* arguments table if any */
71        int blocked : 1;
72        int suspended : 1;
73        int iwannadie : 1;
74        smx_mutex_t mutex;       /* mutex on which the process is blocked  */
75        smx_cond_t cond;         /* cond on which the process is blocked  */
76        xbt_dict_t properties;
77        void *data;              /* kept for compatibility, it should be replaced with moddata */
78        void_f_pvoid_t cleanup_func;
79        void *cleanup_arg;
80
81      } s_smx_process_t;
82 /** @} */
83
84 typedef struct s_smx_process_arg {
85   const char *name;
86   xbt_main_func_t code;
87   void *data;
88   char *hostname;
89   int argc;
90   char **argv;
91   double kill_time;
92   xbt_dict_t properties;
93 } s_smx_process_arg_t, *smx_process_arg_t;
94
95 /*************************** Mutex and Conditional ****************************/
96
97 typedef struct s_smx_mutex {
98
99   /* KEEP IT IN SYNC WITH src/xbt_sg_thread.c::struct s_xbt_mutex */
100   xbt_swag_t sleeping;          /* list of sleeping process */
101   int refcount;
102   /* KEEP IT IN SYNC WITH src/xbt_sg_thread.c::struct s_xbt_mutex */
103
104 } s_smx_mutex_t;
105
106 typedef struct s_smx_cond {
107
108   /* KEEP IT IN SYNC WITH src/xbt_sg_thread.c::struct s_xbt_cond */
109   xbt_swag_t sleeping;          /* list of sleeping process */
110   smx_mutex_t mutex;
111   xbt_fifo_t actions;           /* list of actions */
112   /* KEEP IT IN SYNC WITH src/xbt_sg_thread.c::struct s_xbt_cond */
113
114 } s_smx_cond_t;
115
116 /********************************* Action *************************************/
117
118 /** @brief Action datatype
119     @ingroup m_datatypes_management_details */
120 typedef struct s_smx_action {
121   char *name;              /**< @brief action name if any */
122   xbt_fifo_t cond_list;    /*< conditional variables that must be signaled when the action finish. */
123   void *data;              /**< @brief user data */
124   int refcount;            /**< @brief reference counter */
125   surf_action_t surf_action;    /* SURF modeling of computation  */
126   smx_host_t source;
127 } s_smx_action_t;
128
129 /************************** Configuration support *****************************/
130
131 extern int _simix_init_status;  /* 0: beginning of time; FIXME: KILLME ?
132                                    1: pre-inited (cfg_set created);
133                                    2: inited (running) */
134
135 #define SIMIX_CHECK_HOST()  xbt_assert0(surf_workstation_model->extension.workstation. \
136                                   get_state(SIMIX_host_self()->host)==SURF_RESOURCE_ON,\
137                                   "Host failed, you cannot call this function.")
138
139 smx_host_t __SIMIX_host_create(const char *name, void *workstation, void *data);
140 void __SIMIX_host_destroy(void *host);
141 void __SIMIX_cond_wait(smx_cond_t cond);
142 void __SIMIX_cond_display_actions(smx_cond_t cond);
143 void __SIMIX_action_display_conditions(smx_action_t action);
144 void __SIMIX_create_maestro_process(void);
145
146 /******************************** Context *************************************/
147
148 int SIMIX_context_create_maestro(smx_process_t *process);
149
150 int SIMIX_context_new(smx_process_t *process, xbt_main_func_t code);
151
152 void SIMIX_context_kill(smx_process_t process);
153
154 void SIMIX_context_start(smx_process_t process);
155
156 void SIMIX_context_yield(void);
157
158 void SIMIX_context_schedule(smx_process_t process);
159
160 void SIMIX_context_empty_trash(void);
161
162 void SIMIX_context_stop(int exit_code);
163
164 void SIMIX_context_free(smx_process_t process);
165
166 void SIMIX_context_mod_init(void);
167
168 void SIMIX_context_mod_exit(void);
169 #endif