Logo AND Algorithmique Numérique Distribuée

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