3 /* gras.c - common parts for the Grid Reality And Simulation */
5 /* Authors: Martin Quinson */
6 /* Copyright (C) 2003 the OURAGAN project. */
8 /* This program is free software; you can redistribute it and/or modify it
9 under the terms of the license (GNU LGPL) which comes with this package. */
11 #include "gras_private.h"
13 /**************************************************************************/
14 /**************************************************************************/
16 /**************************************************************************/
17 /**************************************************************************/
19 #ifdef HAVE_LIBPTHREAD
22 /* this is the lock for this module. Every other module will use a void *
23 * as a variable as mutex. */
24 pthread_mutex_t gras_thelock = PTHREAD_MUTEX_INITIALIZER;
29 //fprintf(stderr,"Get Lock... ");
30 #ifdef HAVE_LIBPTHREAD
33 ret = pthread_mutex_lock((pthread_mutex_t *)(&gras_thelock));
35 fprintf(stderr, "gras_lock: Unable to lock (errno = %d)!\n", ret);
39 //fprintf(stderr,"ok\n");
46 // fprintf(stderr,"Release Lock... ");
47 #ifdef HAVE_LIBPTHREAD
50 ret = pthread_mutex_unlock((pthread_mutex_t *)&gras_thelock);
52 fprintf(stderr, "grasReleaseLock: Unable to release lock (errno = %d)!\n", ret);
56 //fprintf(stderr,"ok\n");
60 /* **************************************************************************
61 * Manipulating Callback list
62 * **************************************************************************/
63 gras_cblist_t *gras_cb_get(gras_msgid_t id) {
64 grasProcessData_t *pd=grasProcessDataGet();
67 for (i=0 ; i<pd->grasCblListLen && pd->grasCblList[i].id != id ; i++);
68 return i==pd->grasCblListLen ? NULL : &(pd->grasCblList[i]);
71 gras_error_t gras_cb_create(gras_msgid_t message) {
72 grasProcessData_t *pd=grasProcessDataGet();
74 if (pd->grasCblListLen++) {
75 pd->grasCblList = (gras_cblist_t *)realloc(pd->grasCblList,
76 sizeof(gras_cblist_t)*pd->grasCblListLen);
78 pd->grasCblList = (gras_cblist_t *)malloc(sizeof(gras_cblist_t)*
81 if (!pd->grasCblList) {
82 fprintf(stderr,"PANIC: Malloc error (All callbacks for all hosts are lost)\n");
87 pd->grasCblList[pd->grasCblListLen-1].id=message;
89 pd->grasCblList[pd->grasCblListLen-1].cbCount=0;
90 pd->grasCblList[pd->grasCblListLen-1].cb=NULL;
91 pd->grasCblList[pd->grasCblListLen-1].cbTTL=NULL;
96 /* **************************************************************************
97 * Manipulating User Data
98 * **************************************************************************/
99 void *gras_userdata_get(void) {
100 grasProcessData_t *pd=grasProcessDataGet();
102 return pd ? pd->userdata : NULL;
105 void *gras_userdata_set(void *ud) {
106 grasProcessData_t *pd=grasProcessDataGet();
108 ASSERT(pd,"ProcessData==NULL => This process did not run grasInit()\n");
109 return pd->userdata=ud;