X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/blobdiff_plain/1e32d1f72606b96bb1abd9af359f1590528ec843..806d1314d9398af51ffd016c95b39d173960c659:/include/gras/process.h diff --git a/include/gras/process.h b/include/gras/process.h index 76c2659805..5cf7a16e18 100644 --- a/include/gras/process.h +++ b/include/gras/process.h @@ -1,85 +1,73 @@ -/* $Id$ */ +/* gras/process.h - Manipulating data related to an host. */ -/* gras/core.h - Unsorted part of the GRAS public interface */ - -/* Authors: Martin Quinson */ -/* Copyright (C) 2003 the OURAGAN project. */ +/* Copyright (c) 2004, 2005, 2006, 2007, 2009, 2010. The SimGrid Team. + * All rights reserved. */ /* This program is free software; you can redistribute it and/or modify it - under the terms of the license (GNU LGPL) which comes with this package. */ + * under the terms of the license (GNU LGPL) which comes with this package. */ #ifndef GRAS_PROCESS_H #define GRAS_PROCESS_H -#include /* offsetof() */ -#include /* size_t */ -#include +#include "xbt/misc.h" /* SG_BEGIN_DECL */ +#include "xbt/dict.h" +SG_BEGIN_DECL() -/*! C++ users need love */ -#ifndef BEGIN_DECL -# ifdef __cplusplus -# define BEGIN_DECL extern "C" { -# else -# define BEGIN_DECL -# endif -#endif +/** \addtogroup GRAS_globals + * @{ */ -/*! C++ users need love */ -#ifndef END_DECL -# ifdef __cplusplus -# define END_DECL } -# else -# define END_DECL -# endif -#endif -/* End of cruft for C++ */ +/** \brief Create a new thread */ +void gras_agent_spawn(const char *name, xbt_main_func_t code, + int argc, char *argv[], xbt_dict_t properties); -BEGIN_DECL +/** @} */ -/* ************************************************************************** - * Initializing the processes - * **************************************************************************/ -/** - * gras_process_init: - * - * Perform the various intialisations needed by gras. Each process must run it - */ -gras_error_t gras_process_init(void); +/****************************************************************************/ +/* Manipulating User Data */ +/****************************************************************************/ -/** - * gras_process_exit: +/** \addtogroup GRAS_globals + * \brief Handling global variables so that it works on simulator. + * + * In GRAS, using globals is forbidden since the "processes" will + * sometimes run as a thread inside the same process (namely, in + * simulation mode). So, you have to put all globals in a structure, and + * let GRAS handle it. + * + * Use the \ref gras_userdata_new macro to create a new user data (or malloc it + * and use \ref gras_userdata_set yourself), and \ref gras_userdata_get to + * retrieve a reference to it. + * * - * Frees the memory allocated by gras. Processes should run it + * For more info on this, you may want to check the relevant lesson of the GRAS tutorial: + * \ref GRAS_tut_tour_globals */ -gras_error_t gras_process_exit(void); +/* @{ */ -/****************************************************************************/ -/* Manipulating User Data */ -/****************************************************************************/ /** - * gras_userdata_get: - * - * Get the data associated with the current process. + * \brief Get the data associated with the current process. + * \ingroup GRAS_globals */ -void *gras_userdata_get(void); +XBT_PUBLIC(void *) gras_userdata_get(void); /** - * gras_userdata_set: - * - * Set the data associated with the current process. + * \brief Set the data associated with the current process. + * \ingroup GRAS_globals */ -void *gras_userdata_set(void *ud); +XBT_PUBLIC(void *) gras_userdata_set(void *ud); -/** - * gras_userdata_new: +/** \brief Malloc and set the data associated with the current process. + * + * @warning gras_userdata_new() expects the pointed type, not the + * pointer type. We know it'a a bit troublesome, but it seems like + * the only solution since this macro has to compute the size to + * malloc and should thus know the pointed type. * - * Malloc and set the data associated with the current process. + * You'll find an example in the tutorial: \ref GRAS_tut_tour_globals */ +#define gras_userdata_new(type) ((type*)gras_userdata_set(xbt_new0(type,1))) +/* @} */ -#define gras_userdata_new(type) gras_userdata_set(malloc(sizeof(type))) - -END_DECL - -#endif /* GRAS_PROCESS_H */ - +SG_END_DECL() +#endif /* GRAS_PROCESS_H */