3 /* process - GRAS process handling (common code for RL and SG) */
5 /* Copyright (c) 2003, 2004 Martin Quinson. All rights reserved. */
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. */
10 #include "xbt/sysdep.h"
12 #include "xbt/error.h"
13 #include "gras/transport.h"
14 #include "gras/datadesc.h"
15 #include "gras/messages.h"
16 #include "gras_modinter.h"
18 #include "gras/Virtu/virtu_private.h"
20 XBT_LOG_NEW_DEFAULT_SUBCATEGORY(process,gras,"Process manipulation code");
23 /* Functions to handle gras_procdata_t->libdata cells*/
26 pvoid_f_void_t *creator;
27 void_f_pvoid_t *destructor;
28 } s_gras_procdata_fabric_t, *gras_procdata_fabric_t;
30 static xbt_dynar_t _gras_procdata_fabrics = NULL; /* content: s_gras_procdata_fabric_t */
32 static void gras_procdata_fabric_free(void *fab) {
33 free( ((gras_procdata_fabric_t)fab)->name );
36 /** @brief declare the functions in charge of creating/destructing the procdata of a module
38 * This is intended to be called from the gras_<module>_register function.
40 void gras_procdata_add(const char *name, pvoid_f_void_t creator,void_f_pvoid_t destructor) {
42 gras_procdata_fabric_t fab;
44 if (!_gras_procdata_fabrics) {
45 /* create the dynar if needed */
46 _gras_procdata_fabrics = xbt_dynar_new(sizeof(s_gras_procdata_fabric_t),
47 gras_procdata_fabric_free);
50 fab=xbt_dynar_push_ptr(_gras_procdata_fabrics);
52 fab->name = xbt_strdup(name);
53 fab->creator = creator;
54 fab->destructor = destructor;
57 /* **************************************************************************
59 * **************************************************************************/
60 void *gras_userdata_get(void) {
61 gras_procdata_t *pd=gras_procdata_get();
65 void gras_userdata_set(void *ud) {
66 gras_procdata_t *pd=gras_procdata_get();
71 void *gras_libdata_get(const char *name) {
72 gras_procdata_t *pd=gras_procdata_get();
76 errcode = xbt_dict_get(pd->libdata, name, &res);
77 xbt_assert2(errcode == no_error,
78 "Cannot retrive the libdata associated to %s: %s",
79 name, xbt_error_name(errcode));
85 gras_procdata_init() {
86 gras_procdata_t *pd=gras_procdata_get();
87 s_gras_procdata_fabric_t fab;
95 pd->libdata = xbt_dict_new();
97 xbt_dynar_foreach(_gras_procdata_fabrics,cursor,fab){
99 xbt_assert1(fab.name,"Name of fabric #%d is NULL!",cursor);
100 DEBUG1("Create the procdata for %s",fab.name);
101 /* Check for our own errors */
102 errcode = xbt_dict_get(pd->libdata, fab.name, &data);
103 xbt_assert1(errcode == mismatch_error,
104 "MayDay: two modules use '%s' as libdata name", fab.name);
106 /* Add the data in place */
107 xbt_dict_set(pd->libdata, fab.name, (fab.creator)(), fab.destructor);
113 gras_procdata_exit() {
114 gras_procdata_t *pd=gras_procdata_get();
116 xbt_dict_free(&( pd->libdata ));