Logo AND Algorithmique Numérique Distribuée

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