Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Stringify e_smx_req_t just by using macros (remove the special header)
[simgrid.git] / src / simix / smurf_private.h
1 /* Copyright (c) 2007, 2008, 2009, 2010. The SimGrid Team.
2  * All rights reserved.                                                     */
3
4 /* This program is free software; you can redistribute it and/or modify it
5  * under the terms of the license (GNU LGPL) which comes with this package. */
6
7 #ifndef _SIMIX_SMURF_PRIVATE_H
8 #define _SIMIX_SMURF_PRIVATE_H
9
10 /********************************* Requests ***********************************/
11
12 /* we want to build the e_smx_t enumeration and the table of the corresponding
13  * strings automatically, using macros */
14
15 #define SIMIX_REQ_LIST1 \
16 SIMIX_REQ_ENUM_ELEMENT(REQ_NO_REQ),\
17 SIMIX_REQ_ENUM_ELEMENT(REQ_HOST_GET_BY_NAME),\
18 SIMIX_REQ_ENUM_ELEMENT(REQ_HOST_GET_NAME),\
19 SIMIX_REQ_ENUM_ELEMENT(REQ_HOST_GET_PROPERTIES),\
20 SIMIX_REQ_ENUM_ELEMENT(REQ_HOST_GET_SPEED),\
21 SIMIX_REQ_ENUM_ELEMENT(REQ_HOST_GET_AVAILABLE_SPEED),\
22 SIMIX_REQ_ENUM_ELEMENT(REQ_HOST_GET_STATE),\
23 SIMIX_REQ_ENUM_ELEMENT(REQ_HOST_GET_DATA),\
24 SIMIX_REQ_ENUM_ELEMENT(REQ_HOST_SET_DATA),\
25 SIMIX_REQ_ENUM_ELEMENT(REQ_HOST_EXECUTE),\
26 SIMIX_REQ_ENUM_ELEMENT(REQ_HOST_PARALLEL_EXECUTE),\
27 SIMIX_REQ_ENUM_ELEMENT(REQ_HOST_EXECUTION_DESTROY),\
28 SIMIX_REQ_ENUM_ELEMENT(REQ_HOST_EXECUTION_CANCEL),\
29 SIMIX_REQ_ENUM_ELEMENT(REQ_HOST_EXECUTION_GET_REMAINS),\
30 SIMIX_REQ_ENUM_ELEMENT(REQ_HOST_EXECUTION_GET_STATE),\
31 SIMIX_REQ_ENUM_ELEMENT(REQ_HOST_EXECUTION_SET_PRIORITY),\
32 SIMIX_REQ_ENUM_ELEMENT(REQ_HOST_EXECUTION_WAIT),\
33 SIMIX_REQ_ENUM_ELEMENT(REQ_PROCESS_CREATE),\
34 SIMIX_REQ_ENUM_ELEMENT(REQ_PROCESS_KILL),\
35 SIMIX_REQ_ENUM_ELEMENT(REQ_PROCESS_CHANGE_HOST),\
36 SIMIX_REQ_ENUM_ELEMENT(REQ_PROCESS_SUSPEND),\
37 SIMIX_REQ_ENUM_ELEMENT(REQ_PROCESS_RESUME),\
38 SIMIX_REQ_ENUM_ELEMENT(REQ_PROCESS_COUNT),\
39 SIMIX_REQ_ENUM_ELEMENT(REQ_PROCESS_GET_DATA),\
40 SIMIX_REQ_ENUM_ELEMENT(REQ_PROCESS_SET_DATA),\
41 SIMIX_REQ_ENUM_ELEMENT(REQ_PROCESS_GET_HOST),\
42 SIMIX_REQ_ENUM_ELEMENT(REQ_PROCESS_GET_NAME),\
43 SIMIX_REQ_ENUM_ELEMENT(REQ_PROCESS_IS_SUSPENDED),\
44 SIMIX_REQ_ENUM_ELEMENT(REQ_PROCESS_GET_PROPERTIES),\
45 SIMIX_REQ_ENUM_ELEMENT(REQ_PROCESS_SLEEP),\
46 SIMIX_REQ_ENUM_ELEMENT(REQ_RDV_CREATE),\
47 SIMIX_REQ_ENUM_ELEMENT(REQ_RDV_DESTROY),\
48 SIMIX_REQ_ENUM_ELEMENT(REQ_RDV_GEY_BY_NAME),\
49 SIMIX_REQ_ENUM_ELEMENT(REQ_RDV_COMM_COUNT_BY_HOST),\
50 SIMIX_REQ_ENUM_ELEMENT(REQ_RDV_GET_HEAD),\
51 SIMIX_REQ_ENUM_ELEMENT(REQ_COMM_ISEND),\
52 SIMIX_REQ_ENUM_ELEMENT(REQ_COMM_IRECV),\
53 SIMIX_REQ_ENUM_ELEMENT(REQ_COMM_DESTROY),\
54 SIMIX_REQ_ENUM_ELEMENT(REQ_COMM_CANCEL),\
55 SIMIX_REQ_ENUM_ELEMENT(REQ_COMM_WAITANY),\
56 SIMIX_REQ_ENUM_ELEMENT(REQ_COMM_WAIT),\
57 SIMIX_REQ_ENUM_ELEMENT(REQ_COMM_TEST),\
58 SIMIX_REQ_ENUM_ELEMENT(REQ_COMM_TESTANY),\
59 SIMIX_REQ_ENUM_ELEMENT(REQ_COMM_GET_REMAINS),\
60 SIMIX_REQ_ENUM_ELEMENT(REQ_COMM_GET_STATE),\
61 SIMIX_REQ_ENUM_ELEMENT(REQ_COMM_GET_SRC_DATA),\
62 SIMIX_REQ_ENUM_ELEMENT(REQ_COMM_GET_DST_DATA),\
63 SIMIX_REQ_ENUM_ELEMENT(REQ_COMM_GET_SRC_BUFF),\
64 SIMIX_REQ_ENUM_ELEMENT(REQ_COMM_GET_DST_BUFF),\
65 SIMIX_REQ_ENUM_ELEMENT(REQ_COMM_GET_SRC_BUFF_SIZE),\
66 SIMIX_REQ_ENUM_ELEMENT(REQ_COMM_GET_DST_BUFF_SIZE),\
67 SIMIX_REQ_ENUM_ELEMENT(REQ_COMM_GET_SRC_PROC),\
68 SIMIX_REQ_ENUM_ELEMENT(REQ_COMM_GET_DST_PROC),\
69 SIMIX_REQ_ENUM_ELEMENT(REQ_MUTEX_INIT),\
70 SIMIX_REQ_ENUM_ELEMENT(REQ_MUTEX_DESTROY),\
71 SIMIX_REQ_ENUM_ELEMENT(REQ_MUTEX_LOCK),\
72 SIMIX_REQ_ENUM_ELEMENT(REQ_MUTEX_TRYLOCK),\
73 SIMIX_REQ_ENUM_ELEMENT(REQ_MUTEX_UNLOCK),\
74 SIMIX_REQ_ENUM_ELEMENT(REQ_COND_INIT),\
75 SIMIX_REQ_ENUM_ELEMENT(REQ_COND_DESTROY),\
76 SIMIX_REQ_ENUM_ELEMENT(REQ_COND_SIGNAL),\
77 SIMIX_REQ_ENUM_ELEMENT(REQ_COND_WAIT),\
78 SIMIX_REQ_ENUM_ELEMENT(REQ_COND_WAIT_TIMEOUT),\
79 SIMIX_REQ_ENUM_ELEMENT(REQ_COND_BROADCAST),\
80 SIMIX_REQ_ENUM_ELEMENT(REQ_SEM_INIT),\
81 SIMIX_REQ_ENUM_ELEMENT(REQ_SEM_DESTROY),\
82 SIMIX_REQ_ENUM_ELEMENT(REQ_SEM_RELEASE),\
83 SIMIX_REQ_ENUM_ELEMENT(REQ_SEM_WOULD_BLOCK),\
84 SIMIX_REQ_ENUM_ELEMENT(REQ_SEM_ACQUIRE),\
85 SIMIX_REQ_ENUM_ELEMENT(REQ_SEM_ACQUIRE_TIMEOUT),\
86 SIMIX_REQ_ENUM_ELEMENT(REQ_SEM_GET_CAPACITY)
87
88 /* REQ_COMM_IS_LATENCY_BOUNDED and REQ_SET_CATEGORY make things complicated
89  * because they are not always present */
90 #ifdef HAVE_LATENCY_BOUND_TRACKING
91 #define SIMIX_REQ_LIST2 \
92 ,SIMIX_REQ_ENUM_ELEMENT(REQ_COMM_IS_LATENCY_BOUNDED)
93 #else
94 #define SIMIX_REQ_LIST2
95 #endif
96
97 #ifdef HAVE_TRACING
98 #define SIMIX_REQ_LIST3 \
99 ,SIMIX_REQ_ENUM_ELEMENT(REQ_SET_CATEGORY)
100 #else
101 #define SIMIX_REQ_LIST3
102 #endif
103
104 /* SIMIX_REQ_LIST is the final macro to use */
105 #define SIMIX_REQ_LIST SIMIX_REQ_LIST1 SIMIX_REQ_LIST2 SIMIX_REQ_LIST3
106
107 /* you can redefine the following macro differently to generate something else
108  * with the list of enumeration values (e.g. a table of strings or a table of function pointers) */
109 #define SIMIX_REQ_ENUM_ELEMENT(x) x
110
111 /**
112  * \brief All possible SIMIX requests.
113  */
114 typedef enum {
115 SIMIX_REQ_LIST
116 } e_smx_req_t;
117
118 /**
119  * \brief Represents a SIMIX request.
120  */
121 typedef struct s_smx_req {
122   s_xbt_swag_hookup_t state_hookup;
123   e_smx_req_t call;
124   smx_process_t issuer;
125
126   union {
127
128     struct {
129       const char *name;
130       smx_host_t result;
131     } host_get_by_name;
132
133     struct {
134       smx_host_t host;
135       const char* result;
136     } host_get_name;
137
138     struct {
139       smx_host_t host;
140       xbt_dict_t result;
141     } host_get_properties;
142
143     struct {
144       smx_host_t host;
145       double result;
146     } host_get_speed;
147
148     struct {
149       smx_host_t host;
150       double result;
151     } host_get_available_speed;
152
153     struct {
154       smx_host_t host;
155       int result;
156     } host_get_state;
157
158     struct {
159       smx_host_t host;
160       void* result;
161     } host_get_data;
162
163     struct {
164       smx_host_t host;
165       void* data;
166     } host_set_data;
167
168     struct {
169       const char* name;
170       smx_host_t host;
171       double computation_amount;
172       smx_action_t result;
173     } host_execute;
174
175     struct {
176       const char *name;
177       int host_nb;
178       smx_host_t *host_list;
179       double *computation_amount;
180       double *communication_amount;
181       double amount;
182       double rate;
183       smx_action_t result;
184     } host_parallel_execute;
185
186     struct {
187       smx_action_t execution;
188     } host_execution_destroy;
189
190     struct {
191       smx_action_t execution;
192     } host_execution_cancel;
193
194     struct {
195       smx_action_t execution;
196       double result;
197     } host_execution_get_remains;
198
199     struct {
200       smx_action_t execution;
201       e_smx_state_t result;
202     } host_execution_get_state;
203
204     struct {
205       smx_action_t execution;
206       double priority;
207     } host_execution_set_priority;
208
209     struct {
210       smx_action_t execution;
211     } host_execution_wait;
212
213     struct {
214       const char *name;
215       xbt_main_func_t code;
216       void *data;
217       const char *hostname;
218       int argc;
219       char **argv;
220       xbt_dict_t properties;
221       smx_process_t result;
222     } process_create;
223
224     struct {
225       smx_process_t process;
226     } process_kill;
227
228     struct {
229       smx_process_t process;
230       const char *source;
231       const char *dest;
232     } process_change_host;
233
234     struct {
235       smx_process_t process;
236     } process_suspend;
237
238     struct {
239       smx_process_t process;
240     } process_resume;
241
242     struct {
243       int result;
244     } process_count;
245
246     struct {
247       smx_process_t process;
248       void* result;
249     } process_get_data;
250
251     struct {
252       smx_process_t process;
253       void* data;
254     } process_set_data;
255
256     struct {
257       smx_process_t process;
258       smx_host_t result;
259     } process_get_host;
260
261     struct {
262       smx_process_t process;
263       const char *result;
264     } process_get_name;
265
266     struct {
267       smx_process_t process;
268       int result;
269     } process_is_suspended;
270
271     struct {
272       smx_process_t process;
273       xbt_dict_t result;
274     } process_get_properties;
275
276     struct {
277       double duration;
278       e_smx_state_t result;
279     } process_sleep;
280
281     struct {
282       const char *name;
283       smx_rdv_t result;
284     } rdv_create;
285
286     struct {
287       smx_rdv_t rdv;
288     } rdv_destroy;
289
290     struct {
291       const char* name;
292       smx_rdv_t result;
293     } rdv_get_by_name;
294
295     struct {
296       smx_rdv_t rdv;
297       smx_host_t host;
298       unsigned int result; 
299     } rdv_comm_count_by_host;
300
301     struct {
302       smx_rdv_t rdv;
303       smx_action_t result;
304     } rdv_get_head;
305
306     struct {
307       smx_rdv_t rdv;
308       double task_size;
309       double rate;
310       void *src_buff;
311       size_t src_buff_size;
312       int (*match_fun)(void *, void *);
313       void *data;
314       smx_action_t result;
315     } comm_isend;
316
317     struct {
318       smx_rdv_t rdv;
319       void *dst_buff;
320       size_t *dst_buff_size;
321       int (*match_fun)(void *, void *);
322           void *data;
323       smx_action_t result;
324     } comm_irecv;
325
326     struct {
327       smx_action_t comm;
328     } comm_destroy;
329
330     struct {
331       smx_action_t comm;
332     } comm_cancel;
333
334     struct {
335       xbt_dynar_t comms;
336       unsigned int result;
337     } comm_waitany;
338
339     struct {
340       smx_action_t comm;
341       double timeout;
342     } comm_wait;
343
344     struct {
345       smx_action_t comm;
346       int result;
347     } comm_test;
348
349     struct {
350       xbt_dynar_t comms;
351       int result;
352     } comm_testany;
353
354     struct {
355       smx_action_t comm;
356       double result;
357     } comm_get_remains;
358
359     struct {
360       smx_action_t comm;
361       e_smx_state_t result;
362     } comm_get_state;
363
364     struct {
365       smx_action_t comm;
366       void *result;
367     } comm_get_src_data;
368
369     struct {
370       smx_action_t comm;
371       void *result;
372     } comm_get_dst_data;
373
374     struct {
375       smx_action_t comm;
376       void *result;
377     } comm_get_src_buff;
378
379     struct {
380       smx_action_t comm;
381       void *result;
382     } comm_get_dst_buff;
383
384     struct {
385       smx_action_t comm;
386       size_t result;
387     } comm_get_src_buff_size;
388
389     struct {
390       smx_action_t comm;
391       size_t result;
392     } comm_get_dst_buff_size;
393
394     struct {
395       smx_action_t comm;
396       smx_process_t result;
397     } comm_get_src_proc;
398
399     struct {
400       smx_action_t comm;
401       smx_process_t result;
402     } comm_get_dst_proc;
403
404 #ifdef HAVE_LATENCY_BOUND_TRACKING
405     struct {
406       smx_action_t comm;
407       int result;
408     } comm_is_latency_bounded;
409 #endif
410
411 #ifdef HAVE_TRACING
412     struct {
413       smx_action_t action;
414       const char *category;
415     } set_category;
416 #endif
417
418     struct {
419       smx_mutex_t result;
420     } mutex_init;
421
422     struct {
423       smx_mutex_t mutex;
424     } mutex_lock;
425
426     struct {
427       smx_mutex_t mutex;
428       int result;
429     } mutex_trylock;
430
431     struct {
432       smx_mutex_t mutex;
433     } mutex_unlock;
434
435     struct {
436       smx_mutex_t mutex;
437     } mutex_destroy;
438
439     struct {
440       smx_cond_t result;
441     } cond_init;
442
443     struct {
444       smx_cond_t cond;
445     } cond_destroy;
446
447     struct {
448       smx_cond_t cond;
449     } cond_signal;
450
451     struct {
452       smx_cond_t cond;
453       smx_mutex_t mutex;
454     } cond_wait;
455
456     struct {
457       smx_cond_t cond;
458       smx_mutex_t mutex;
459       double timeout;
460     } cond_wait_timeout;
461
462     struct {
463       smx_cond_t cond;
464     } cond_broadcast;
465
466     struct {
467       int capacity;
468       smx_sem_t result;
469     } sem_init;
470
471     struct {
472       smx_sem_t sem;
473     } sem_destroy;
474
475     struct {
476       smx_sem_t sem;
477     } sem_release;
478
479     struct {
480       smx_sem_t sem;
481       int result;
482     } sem_would_block;
483
484     struct {
485       smx_sem_t sem;
486     } sem_acquire;
487
488     struct {
489       smx_sem_t sem;
490       double timeout;
491     } sem_acquire_timeout;
492
493     struct {
494       smx_sem_t sem;
495       int result;
496     } sem_get_capacity;
497   };
498 } s_smx_req_t, *smx_req_t;
499
500 /******************************** General *************************************/
501
502 void SIMIX_request_init(void);
503 void SIMIX_request_destroy(void);
504 void SIMIX_request_push(void);
505 smx_req_t SIMIX_request_pop(void);
506 void SIMIX_request_answer(smx_req_t);
507 void SIMIX_request_pre(smx_req_t, int);
508 void SIMIX_request_post(smx_action_t);
509 XBT_INLINE smx_req_t SIMIX_req_mine(void);
510
511 #endif
512