Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
bcf61c9dcad805db74872bef2a3b435bfa382635
[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 "simix/context.h"
19 #include "xbt/config.h"
20 #include "xbt/function_types.h"
21
22 /******************************* Datatypes **********************************/
23
24
25 /********************************** Host ************************************/
26
27 /** @brief Host datatype 
28     @ingroup m_datatypes_management_details */
29 typedef struct s_smx_host {
30   char *name;              /**< @brief host name if any */
31   void *host;              /* SURF modeling */
32   xbt_swag_t process_list;
33   void *data;              /**< @brief user data */
34 } s_smx_host_t;
35
36 /********************************* Simix Global ******************************/
37
38 typedef struct SIMIX_Global {
39   xbt_dict_t host;
40   xbt_swag_t process_to_run;
41   xbt_swag_t process_list;
42
43   smx_process_t current_process;
44   xbt_dict_t registered_functions;
45   smx_creation_func_t create_process_function;
46   void_f_pvoid_t kill_process_function;
47   void_f_pvoid_t cleanup_process_function;
48 } s_SIMIX_Global_t, *SIMIX_Global_t;
49
50 extern SIMIX_Global_t simix_global;
51
52 /******************************* Process *************************************/
53
54 /** @brief Process datatype 
55     @ingroup m_datatypes_management_details @{ */
56      typedef struct s_smx_process {
57        s_xbt_swag_hookup_t process_hookup;
58        s_xbt_swag_hookup_t synchro_hookup;
59        s_xbt_swag_hookup_t host_proc_hookup;
60
61        char *name;              /**< @brief process name if any */
62        smx_host_t smx_host;     /* the host on which the process is running */
63        xbt_context_t context;   /* the context that executes the scheduler function */
64        int argc;                /* arguments number if any */
65        char **argv;             /* arguments table if any */
66        int blocked : 1;
67        int suspended : 1;
68        int iwannadie : 1;
69        smx_mutex_t mutex;       /* mutex on which the process is blocked  */
70        smx_cond_t cond;         /* cond on which the process is blocked  */
71        xbt_dict_t properties;
72        void *data;              /* kept for compatibility, it should be replaced with moddata */
73
74      } s_smx_process_t;
75 /** @} */
76
77 typedef struct s_smx_process_arg {
78   const char *name;
79   xbt_main_func_t code;
80   void *data;
81   char *hostname;
82   int argc;
83   char **argv;
84   double kill_time;
85   xbt_dict_t properties;
86 } s_smx_process_arg_t, *smx_process_arg_t;
87
88 /********************************* Mutex and Conditional ****************************/
89
90 typedef struct s_smx_mutex {
91
92   /* KEEP IT IN SYNC WITH src/xbt_sg_thread.c::struct s_xbt_mutex */
93   xbt_swag_t sleeping;          /* list of sleeping process */
94   int refcount;
95   /* KEEP IT IN SYNC WITH src/xbt_sg_thread.c::struct s_xbt_mutex */
96
97 } s_smx_mutex_t;
98
99 typedef struct s_smx_cond {
100
101   /* KEEP IT IN SYNC WITH src/xbt_sg_thread.c::struct s_xbt_cond */
102   xbt_swag_t sleeping;          /* list of sleeping process */
103   smx_mutex_t mutex;
104   xbt_fifo_t actions;           /* list of actions */
105   /* KEEP IT IN SYNC WITH src/xbt_sg_thread.c::struct s_xbt_cond */
106
107 } s_smx_cond_t;
108
109 /********************************* Action **************************************/
110
111 typedef struct s_smx_simdata_action {
112   surf_action_t surf_action;    /* SURF modeling of computation  */
113
114   smx_host_t source;
115
116 } s_smx_simdata_action_t;
117
118
119
120 /******************************* Other **********************************/
121
122
123 #define SIMIX_CHECK_HOST()  xbt_assert0(surf_workstation_model->extension.workstation. \
124                                   get_state(SIMIX_host_self()->host)==SURF_RESOURCE_ON,\
125                                   "Host failed, you cannot call this function.")
126
127 smx_host_t __SIMIX_host_create(const char *name, void *workstation,
128                                void *data);
129 void __SIMIX_host_destroy(void *host);
130
131 void __SIMIX_cond_wait(smx_cond_t cond);
132
133 void __SIMIX_cond_display_actions(smx_cond_t cond);
134 void __SIMIX_action_display_conditions(smx_action_t action);
135
136 #endif