diff options
author | goodale <goodale@1faa4e14-9dd3-4be0-9f0e-ffe519881164> | 2000-10-25 17:48:27 +0000 |
---|---|---|
committer | goodale <goodale@1faa4e14-9dd3-4be0-9f0e-ffe519881164> | 2000-10-25 17:48:27 +0000 |
commit | 30d58b3a4f747fc7fd732492df06abcc2c5bd6d6 (patch) | |
tree | be2d711466125ae9f6d79cc7fe86e08ccde46a25 /src/Startup.c | |
parent | 9e42c49d93494ae88f5e8ead2729ab38706d81f0 (diff) |
Experimental support for threading. Now if you configure with
PTHREADS=yes
and put
httpd::use_pthreads = "yes"
in your parameter file, the polling routine will run in its own thread.
Be careful if you have any http routines which modify data read by non-http
routines, as you run into a potential conflict.
It seems to work, 'though I should probably put a mutex on the steering stuff in
case the queue gets dispatched at the same time as someone is adding to it...
Tom
git-svn-id: http://svn.cactuscode.org/arrangements/CactusConnect/HTTPD/trunk@95 1faa4e14-9dd3-4be0-9f0e-ffe519881164
Diffstat (limited to 'src/Startup.c')
-rw-r--r-- | src/Startup.c | 137 |
1 files changed, 132 insertions, 5 deletions
diff --git a/src/Startup.c b/src/Startup.c index dd77cbe..3047242 100644 --- a/src/Startup.c +++ b/src/Startup.c @@ -3,7 +3,7 @@ @date Wed Sep 13 21:26:56 2000 @author Tom Goodale @desc - + Scheduled routines for the HTTPD thorn. @enddesc @version $Header$ @@*/ @@ -12,6 +12,7 @@ #include <stdlib.h> #include "cctk.h" +#include "cctk_Parameter.h" #include "cctk_Arguments.h" #include "cctk_Parameters.h" @@ -19,9 +20,43 @@ #include "httpd.h" #include "http_Steer.h" +#ifdef PTHREADS +#include <pthread.h> +#endif + static char *rcsid = "$Header$"; -CCTK_FILEVERSION(DevThorn_http_Startup_c) +CCTK_FILEVERSION(CactusConnect_HTTPD_Startup_c) + +/******************************************************************** + ********************* Local Data Types *********************** + ********************************************************************/ + +/******************************************************************** + ********************* Local Routine Prototypes ********************* + ********************************************************************/ + +static void * HTTP_THread(void *cctkGH); +static void HTTP_SetupPollingThread(cGH *cctkGH); + +/******************************************************************** + ********************* Other Routine Prototypes ********************* + ********************************************************************/ + +/******************************************************************** + ********************* Local Data ***************************** + ********************************************************************/ + +#ifdef PTHREADS +static pthread_t polling_thread; +static int thread_started = 0; +#endif + +/******************************************************************** + ********************* External Routines ********************** + ********************************************************************/ + + /*@@ @routine HTTP_Startup @@ -62,7 +97,7 @@ int HTTP_Startup(void) { HTTP_Poll(NULL, state.timeout_seconds, state.timeout_useconds); } - + if(state.steer == 1) { HTTP_SteerDispatch(); @@ -101,14 +136,28 @@ void HTTP_Work(CCTK_ARGUMENTS) httpState state; +#ifdef PTHREADS + if(CCTK_MyProc(cctkGH) == 0 && use_pthreads && ! thread_started) + { + HTTP_SetupPollingThread(cctkGH); + } +#endif + HTTP_UpdateState(cctkGH, &state); do { - if(CCTK_MyProc(cctkGH) == 0) +#ifdef PTHREADS + if(!use_pthreads) { - HTTP_Poll(cctkGH, state.timeout_seconds, state.timeout_useconds); +#endif + if(CCTK_MyProc(cctkGH) == 0) + { + HTTP_Poll(cctkGH, state.timeout_seconds, state.timeout_useconds); + } +#ifdef PTHREADS } +#endif if(state.steer == 1) { @@ -150,3 +199,81 @@ int HTTP_Shutdown(void) return 0; } + +/******************************************************************** + ********************* Local Routines ************************* + ********************************************************************/ + + /*@@ + @routine HTTP_Thread + @date Wed Oct 25 17:04:59 2000 + @author Tom Goodale + @desc + The http thread routine. + @enddesc + @calls + @calledby + @history + + @endhistory + @var cctkGH + @vdesc The cGH + @vtype cGH * + @vio inout + @vcomment + + @endvar + +@@*/ +static void * HTTP_Thread(void *cctkGH) +{ + CCTK_INT *terminate; + CCTK_INT type; + + do + { + /* Only poll for a few seconds in case we are terminated */ + HTTP_Poll((cGH *)cctkGH, 10, 0); + + terminate = (CCTK_INT *)CCTK_ParameterGet("terminate",CCTK_THORNSTRING, &type); + + } while(! *terminate); + + return NULL; +} + + /*@@ + @routine HTTP_SetupPollingThread + @date Wed Oct 25 17:05:38 2000 + @author Tom Goodale + @desc + Sets up the http polling thread. + @enddesc + @calls + @calledby + @history + + @endhistory + @var cctkGH + @vdesc The cGH + @vtype cGH * + @vio inout + @vcomment + + @endvar + +@@*/ +static void HTTP_SetupPollingThread(cGH *cctkGH) +{ +#ifdef PTHREADS + if(pthread_create(&polling_thread, NULL, HTTP_Thread, (void *)cctkGH)) + { + perror("pthread_create: "); + CCTK_Exit(cctkGH,99); + } + else + { + thread_started = 1; + } +#endif +} |