diff src/c/request.c @ 1522:4d0b80dd4c37

Introduce URWEB_STACK_SIZE environment variable (based on a patch by Hao Deng)
author Adam Chlipala <adam@chlipala.net>
date Tue, 02 Aug 2011 14:31:37 -0400
parents 36f7d1debb37
children 27fdd78bd2f5
line wrap: on
line diff
--- a/src/c/request.c	Tue Aug 02 13:48:26 2011 -0400
+++ b/src/c/request.c	Tue Aug 02 14:31:37 2011 -0400
@@ -123,12 +123,40 @@
   };
 }
 
+static unsigned long long stackSize;
+
+int pthread_create_big(pthread_t *outThread, void *foo, void *threadFunc, void *arg)
+{
+  int err;
+  pthread_attr_t stackSizeAttribute;
+
+  err = pthread_attr_init(&stackSizeAttribute);
+  if (err) return err; 
+
+  if (stackSize > 0) {
+    err = pthread_attr_setstacksize(&stackSizeAttribute, stackSize);
+    if (err) return err;
+  }
+
+  return pthread_create(outThread, &stackSizeAttribute, threadFunc, arg);
+}
+
 void uw_request_init(uw_app *app, void *logger_data, uw_logger log_error, uw_logger log_debug) {
   uw_context ctx;
   failure_kind fk;
   uw_periodic *ps;
   loggers *ls = malloc(sizeof(loggers));
   int id;
+  char *stackSize_s;
+
+  if ((stackSize_s = getenv("URWEB_STACK_SIZE")) != NULL && stackSize_s[0] != 0) {
+    stackSize = atoll(stackSize_s);
+
+    if (stackSize <= 0) {
+      fprintf(stderr, "Invalid stack size \"%s\"\n", stackSize_s);
+      exit(1);
+    }
+  }
 
   ls->app = app;
   ls->logger_data = logger_data;
@@ -141,7 +169,7 @@
   {
     pthread_t thread;
     
-    if (uw_time_max && pthread_create(&thread, NULL, ticker, NULL)) {
+    if (uw_time_max && pthread_create_big(&thread, NULL, ticker, NULL)) {
       fprintf(stderr, "Error creating ticker thread\n");
       exit(1);
     }
@@ -174,7 +202,7 @@
     arg->ls = ls;
     arg->pdic = *ps;
     
-    if (pthread_create(&thread, NULL, periodic_loop, arg)) {
+    if (pthread_create_big(&thread, NULL, periodic_loop, arg)) {
       fprintf(stderr, "Error creating periodic thread\n");
       exit(1);
     }