3 /* Copyright (c) 2007 Arnaud Legrand, Bruno Donnassolo.
\r
4 All rights reserved. */
\r
6 /* This program is free software; you can redistribute it and/or modify it
\r
7 * under the terms of the license (GNU LGPL) which comes with this package. */
\r
9 #ifndef SIMIX_PRIVATE_H
\r
10 #define SIMIX_PRIVATE_H
\r
13 #include "simix/simix.h"
\r
14 #include "surf/surf.h"
\r
15 #include "xbt/fifo.h"
\r
16 #include "xbt/swag.h"
\r
17 #include "xbt/dict.h"
\r
18 #include "xbt/config.h"
\r
19 #include "xbt/function_types.h"
\r
21 /******************************** Datatypes ***********************************/
\r
24 /*********************************** Host *************************************/
\r
26 /** @brief Host datatype
\r
27 @ingroup m_datatypes_management_details */
\r
28 typedef struct s_smx_host {
\r
29 char *name; /**< @brief host name if any */
\r
30 void *host; /* SURF modeling */
\r
31 xbt_swag_t process_list;
\r
32 void *data; /**< @brief user data */
\r
35 /********************************** Simix Global ******************************/
\r
37 typedef struct s_smx_context_factory *smx_context_factory_t;
\r
39 typedef struct SIMIX_Global {
\r
40 smx_context_factory_t context_factory;
\r
42 xbt_swag_t process_to_run;
\r
43 xbt_swag_t process_list;
\r
44 xbt_swag_t process_to_destroy;
\r
45 smx_process_t current_process;
\r
46 smx_process_t maestro_process;
\r
47 xbt_dict_t registered_functions;
\r
48 smx_creation_func_t create_process_function;
\r
49 void_f_pvoid_t kill_process_function;
\r
50 void_f_pvoid_t cleanup_process_function;
\r
51 } s_SIMIX_Global_t, *SIMIX_Global_t;
\r
53 extern SIMIX_Global_t simix_global;
\r
55 /******************************** Process *************************************/
\r
57 typedef struct s_xbt_context *xbt_context_t;
\r
59 /** @brief Process datatype
\r
60 @ingroup m_datatypes_management_details @{ */
\r
61 typedef struct s_smx_process {
\r
62 s_xbt_swag_hookup_t process_hookup;
\r
63 s_xbt_swag_hookup_t synchro_hookup;
\r
64 s_xbt_swag_hookup_t host_proc_hookup;
\r
65 s_xbt_swag_hookup_t destroy_hookup;
\r
67 char *name; /**< @brief process name if any */
\r
68 smx_host_t smx_host; /* the host on which the process is running */
\r
69 xbt_context_t context; /* the context that executes the scheduler function */
\r
70 int argc; /* arguments number if any */
\r
71 char **argv; /* arguments table if any */
\r
75 smx_mutex_t mutex; /* mutex on which the process is blocked */
\r
76 smx_cond_t cond; /* cond on which the process is blocked */
\r
77 xbt_dict_t properties;
\r
78 void *data; /* kept for compatibility, it should be replaced with moddata */
\r
79 void_f_pvoid_t cleanup_func;
\r
85 typedef struct s_smx_process_arg {
\r
87 xbt_main_func_t code;
\r
93 xbt_dict_t properties;
\r
94 } s_smx_process_arg_t, *smx_process_arg_t;
\r
96 /*************************** Mutex and Conditional ****************************/
\r
98 typedef struct s_smx_mutex {
\r
100 /* KEEP IT IN SYNC WITH src/xbt_sg_thread.c::struct s_xbt_mutex */
\r
101 xbt_swag_t sleeping; /* list of sleeping process */
\r
103 /* KEEP IT IN SYNC WITH src/xbt_sg_thread.c::struct s_xbt_mutex */
\r
107 typedef struct s_smx_cond {
\r
109 /* KEEP IT IN SYNC WITH src/xbt_sg_thread.c::struct s_xbt_cond */
\r
110 xbt_swag_t sleeping; /* list of sleeping process */
\r
112 xbt_fifo_t actions; /* list of actions */
\r
113 /* KEEP IT IN SYNC WITH src/xbt_sg_thread.c::struct s_xbt_cond */
\r
117 /********************************* Action *************************************/
\r
119 /** @brief Action datatype
\r
120 @ingroup m_datatypes_management_details */
\r
121 typedef struct s_smx_action {
\r
122 char *name; /**< @brief action name if any */
\r
123 xbt_fifo_t cond_list; /*< conditional variables that must be signaled when the action finish. */
\r
124 void *data; /**< @brief user data */
\r
125 int refcount; /**< @brief reference counter */
\r
126 surf_action_t surf_action; /* SURF modeling of computation */
\r
130 /******************************* Other **********************************/
\r
133 #define SIMIX_CHECK_HOST() xbt_assert0(surf_workstation_model->extension.workstation. \
\r
134 get_state(SIMIX_host_self()->host)==SURF_RESOURCE_ON,\
\r
135 "Host failed, you cannot call this function.")
\r
137 smx_host_t __SIMIX_host_create(const char *name, void *workstation, void *data);
\r
138 void __SIMIX_host_destroy(void *host);
\r
139 void __SIMIX_cond_wait(smx_cond_t cond);
\r
140 void __SIMIX_cond_display_actions(smx_cond_t cond);
\r
141 void __SIMIX_action_display_conditions(smx_action_t action);
\r
142 void __SIMIX_create_maestro_process(void);
\r
144 /******************************** Context *************************************/
\r
146 int SIMIX_context_create_maestro(smx_process_t *process);
\r
148 int SIMIX_context_new(smx_process_t *process, xbt_main_func_t code);
\r
149 \rvoid SIMIX_context_kill(smx_process_t process);
\r
150 \rvoid SIMIX_context_start(smx_process_t process);
\r
151 \rvoid SIMIX_context_yield(void);
\r
152 \rvoid SIMIX_context_schedule(smx_process_t process);
\r
153 \rvoid SIMIX_context_empty_trash(void);
\r
155 void SIMIX_context_stop(int exit_code);
\r
156 \rvoid SIMIX_context_free(smx_process_t process);
\r
158 void SIMIX_context_mod_init(void);
\r
160 void SIMIX_context_mod_exit(void);
\r