Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
91252f0116bef4b5aa120a0e2642c1b147ebd327
[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/context.h"
19 #include "xbt/config.h"
20
21 /******************************* Datatypes **********************************/
22
23
24 /********************************** Host ************************************/
25
26 typedef struct s_smx_simdata_host {
27   void *host;                   /* SURF modeling */
28   xbt_swag_t process_list;
29 } s_smx_simdata_host_t;
30
31 /********************************* Simix Global ******************************/
32
33 typedef struct SIMIX_Global {
34   xbt_fifo_t host;
35   xbt_swag_t process_to_run;
36   xbt_swag_t process_list;
37
38   smx_process_t current_process;
39   xbt_dict_t registered_functions;
40         void* (*create_process_function) ();
41         void* (*kill_process_function)();
42 } s_SIMIX_Global_t, *SIMIX_Global_t;
43
44 extern SIMIX_Global_t simix_global;
45
46 /******************************* Process *************************************/
47
48 typedef struct s_smx_simdata_process {
49   smx_host_t s_host;                /* the host on which the process is running */
50   xbt_context_t context;                /* the context that executes the scheduler fonction */
51   int blocked;
52   int suspended;
53   smx_mutex_t mutex;            /* mutex on which the process is blocked  */
54   smx_cond_t cond;              /* cond on which the process is blocked  */
55   int argc;                     /* arguments number if any */
56   char **argv;                  /* arguments table if any */
57 } s_smx_simdata_process_t;
58
59 typedef struct s_smx_process_arg {
60   const char *name;
61   smx_process_code_t code;
62   void *data;
63   char *hostname;
64   int argc;
65   char **argv;
66   double kill_time;
67 } s_smx_process_arg_t, *smx_process_arg_t;
68
69 /********************************* Mutex and Conditional ****************************/
70
71 typedef struct s_smx_mutex {
72
73    /* KEEP IT IN SYNC WITH src/xbt_sg_thread.c::struct s_xbt_mutex */
74    xbt_swag_t sleeping;                 /* list of sleeping process */
75    int using;
76    /* KEEP IT IN SYNC WITH src/xbt_sg_thread.c::struct s_xbt_mutex */
77
78 } s_smx_mutex_t;
79
80 typedef struct s_smx_cond {
81    
82    /* KEEP IT IN SYNC WITH src/xbt_sg_thread.c::struct s_xbt_cond */
83    xbt_swag_t sleeping;                         /* list of sleeping process */
84    smx_mutex_t  mutex;
85    xbt_fifo_t actions;                  /* list of actions */
86    /* KEEP IT IN SYNC WITH src/xbt_sg_thread.c::struct s_xbt_cond */
87
88 } s_smx_cond_t;
89
90 /********************************* Action **************************************/
91
92 typedef struct s_smx_simdata_action {
93   surf_action_t surf_action;    /* SURF modeling of computation  */
94   
95   smx_host_t source; 
96
97 } s_smx_simdata_action_t;
98
99
100
101 /******************************* Configuration support **********************************/
102
103 void simix_config_init(void); /* create the config set, call this before use! */
104 void simix_config_finalize(void); /* destroy the config set, call this at cleanup. */
105 extern int _simix_init_status; /* 0: beginning of time; 
106                                 1: pre-inited (cfg_set created); 
107                                 2: inited (running) */
108 extern xbt_cfg_t _simix_cfg_set;
109
110
111 #define SIMIX_CHECK_HOST()  xbt_assert0(surf_workstation_resource->extension_public-> \
112                                   get_state(SIMIX_host_self()->simdata->host)==SURF_CPU_ON,\
113                                   "Host failed, you cannot call this function.")
114
115 smx_host_t __SIMIX_host_create(const char *name, void *workstation, void *data);
116 void __SIMIX_host_destroy(smx_host_t host);
117
118 void __SIMIX_cond_wait(smx_cond_t cond);
119
120 #endif