From 67e78d93e56222ee7b8b7e95e66d87f4cc5452f6 Mon Sep 17 00:00:00 2001 From: goodale Date: Wed, 25 Oct 2000 18:47:25 +0000 Subject: Putting a mutex on the steering as there is a potential race condition here if the http thread steers a parameter at the same time as the main thread dispatches the queue. Tom git-svn-id: http://svn.cactuscode.org/arrangements/CactusConnect/HTTPD/trunk@96 1faa4e14-9dd3-4be0-9f0e-ffe519881164 --- src/Steer.c | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) (limited to 'src/Steer.c') diff --git a/src/Steer.c b/src/Steer.c index d1da668..2f89e9b 100644 --- a/src/Steer.c +++ b/src/Steer.c @@ -17,6 +17,10 @@ #include #include +#ifdef PTHREADS +#include +#endif + #ifdef CCTK_MPI #include "mpi.h" #endif @@ -55,6 +59,10 @@ static int SteerParameters(void); static char *queuebuffer = NULL; static int queuebuffer_size = 0; +#ifdef PTHREADS +static pthread_mutex_t steer_mutex = PTHREAD_MUTEX_INITIALIZER; +#endif + /******************************************************************** ********************* External Routines ********************** ********************************************************************/ @@ -82,6 +90,10 @@ int HTTP_SteerQueue(const char *thorn, const char *parameter, const char *value) retval = 0; +#ifdef PTHREADS + pthread_mutex_lock(&steer_mutex); +#endif + buffer_length = queuebuffer ? strlen(queuebuffer) : 0; /* Added length will be lengthof(thorn::par=val\n) */ @@ -110,6 +122,10 @@ int HTTP_SteerQueue(const char *thorn, const char *parameter, const char *value) thorn,parameter, value); } +#ifdef PTHREADS + pthread_mutex_unlock(&steer_mutex); +#endif + return retval; } @@ -129,10 +145,18 @@ int HTTP_SteerQueue(const char *thorn, const char *parameter, const char *value) @@*/ int HTTP_SteerDispatch(void) { +#ifdef PTHREADS + pthread_mutex_lock(&steer_mutex); +#endif + CommunicateBuffer(); SteerParameters(); +#ifdef PTHREADS + pthread_mutex_unlock(&steer_mutex); +#endif + return 0; } -- cgit v1.2.3