Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
cosmetics
[simgrid.git] / include / gras / process.h
1 /* $Id$ */
2
3 /* gras/process.h - Manipulating data related to an host.                   */
4
5 /* Copyright (c) 2003, 2004 Martin Quinson. All rights reserved.            */
6
7 /* This program is free software; you can redistribute it and/or modify it
8  * under the terms of the license (GNU LGPL) which comes with this package. */
9
10 #ifndef GRAS_PROCESS_H
11 #define GRAS_PROCESS_H
12
13 #include "xbt/misc.h"           /* SG_BEGIN_DECL */
14 #include "xbt/dict.h"
15
16 SG_BEGIN_DECL()
17
18      void gras_agent_spawn(const char *name, void *data, xbt_main_func_t code,
19                            int argc, char *argv[], xbt_dict_t properties);
20
21
22 /****************************************************************************/
23 /* Manipulating User Data                                                   */
24 /****************************************************************************/
25
26 /** \addtogroup GRAS_globals
27  *  \brief Handling global variables so that it works on simulator.
28  * 
29  * In GRAS, using globals is forbidden since the "processes" will
30  * sometimes run as a thread inside the same process (namely, in
31  * simulation mode). So, you have to put all globals in a structure, and
32  * let GRAS handle it.
33  * 
34  * Use the \ref gras_userdata_new macro to create a new user data (or malloc it
35  * and use \ref gras_userdata_set yourself), and \ref gras_userdata_get to
36  * retrieve a reference to it.
37  * 
38  * 
39  * For more info on this, you may want to check the relevant lesson of the GRAS tutorial:
40  * \ref GRAS_tut_tour_globals
41  */
42 /* @{ */
43
44 /**
45  * \brief Get the data associated with the current process.
46  * \ingroup GRAS_globals
47  */
48 XBT_PUBLIC(void *) gras_userdata_get(void);
49
50 /**
51  * \brief Set the data associated with the current process.
52  * \ingroup GRAS_globals
53  */
54 XBT_PUBLIC(void *) gras_userdata_set(void *ud);
55
56 /** \brief Malloc and set the data associated with the current process.
57  *
58  * @warnig gras_userdata_new() expects the pointed type, not the
59  * pointer type. We know it'a a bit troublesome, but it seems like
60  * the only solution since this macro has to compute the size to
61  * malloc and should thus know the pointed type. 
62  *
63  * You'll find an example in the tutorial:  \ref GRAS_tut_tour_globals
64  */
65 #define gras_userdata_new(type) ((type*)gras_userdata_set(xbt_new0(type,1)))
66 /* @} */
67
68 SG_END_DECL()
69 #endif /* GRAS_PROCESS_H */