3 /* Copyright (c) 2007 Arnaud Legrand, Bruno Donnassolo.
4 All rights reserved. */
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. */
9 #ifndef SIMIX_PRIVATE_H
10 #define SIMIX_PRIVATE_H
13 #include "simix/simix.h"
14 #include "surf/surf.h"
18 #include "xbt/function_types.h"
20 /******************************** Datatypes ***********************************/
23 /*********************************** Host *************************************/
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 */
34 /********************************** Simix Global ******************************/
36 typedef struct s_smx_context_factory *smx_context_factory_t;
38 typedef struct SIMIX_Global {
39 smx_context_factory_t context_factory;
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;
52 extern SIMIX_Global_t simix_global;
54 /******************************** Process *************************************/
56 typedef struct s_smx_context *smx_context_t;
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;
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 */
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;
84 typedef struct s_smx_process_arg {
92 xbt_dict_t properties;
93 } s_smx_process_arg_t, *smx_process_arg_t;
95 /*************************** Mutex and Conditional ****************************/
97 typedef struct s_smx_mutex {
99 /* KEEP IT IN SYNC WITH src/xbt_sg_thread.c::struct s_xbt_mutex */
100 xbt_swag_t sleeping; /* list of sleeping process */
102 /* KEEP IT IN SYNC WITH src/xbt_sg_thread.c::struct s_xbt_mutex */
106 typedef struct s_smx_cond {
108 /* KEEP IT IN SYNC WITH src/xbt_sg_thread.c::struct s_xbt_cond */
109 xbt_swag_t sleeping; /* list of sleeping process */
111 xbt_fifo_t actions; /* list of actions */
112 /* KEEP IT IN SYNC WITH src/xbt_sg_thread.c::struct s_xbt_cond */
116 /********************************* Action *************************************/
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 */
129 /************************** Configuration support *****************************/
131 extern int _simix_init_status; /* 0: beginning of time; FIXME: KILLME ?
132 1: pre-inited (cfg_set created);
133 2: inited (running) */
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.")
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);
146 /******************************** Context *************************************/
148 int SIMIX_context_create_maestro(smx_process_t *process);
150 int SIMIX_context_new(smx_process_t *process, xbt_main_func_t code);
152 void SIMIX_context_kill(smx_process_t process);
154 void SIMIX_context_start(smx_process_t process);
156 void SIMIX_context_yield(void);
158 void SIMIX_context_schedule(smx_process_t process);
160 void SIMIX_context_empty_trash(void);
162 void SIMIX_context_stop(int exit_code);
164 void SIMIX_context_free(smx_process_t process);
166 void SIMIX_context_mod_init(void);
168 void SIMIX_context_mod_exit(void);