comparison 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
comparison
equal deleted inserted replaced
1521:001638622c4f 1522:4d0b80dd4c37
121 121
122 sleep(p->pdic.period); 122 sleep(p->pdic.period);
123 }; 123 };
124 } 124 }
125 125
126 static unsigned long long stackSize;
127
128 int pthread_create_big(pthread_t *outThread, void *foo, void *threadFunc, void *arg)
129 {
130 int err;
131 pthread_attr_t stackSizeAttribute;
132
133 err = pthread_attr_init(&stackSizeAttribute);
134 if (err) return err;
135
136 if (stackSize > 0) {
137 err = pthread_attr_setstacksize(&stackSizeAttribute, stackSize);
138 if (err) return err;
139 }
140
141 return pthread_create(outThread, &stackSizeAttribute, threadFunc, arg);
142 }
143
126 void uw_request_init(uw_app *app, void *logger_data, uw_logger log_error, uw_logger log_debug) { 144 void uw_request_init(uw_app *app, void *logger_data, uw_logger log_error, uw_logger log_debug) {
127 uw_context ctx; 145 uw_context ctx;
128 failure_kind fk; 146 failure_kind fk;
129 uw_periodic *ps; 147 uw_periodic *ps;
130 loggers *ls = malloc(sizeof(loggers)); 148 loggers *ls = malloc(sizeof(loggers));
131 int id; 149 int id;
150 char *stackSize_s;
151
152 if ((stackSize_s = getenv("URWEB_STACK_SIZE")) != NULL && stackSize_s[0] != 0) {
153 stackSize = atoll(stackSize_s);
154
155 if (stackSize <= 0) {
156 fprintf(stderr, "Invalid stack size \"%s\"\n", stackSize_s);
157 exit(1);
158 }
159 }
132 160
133 ls->app = app; 161 ls->app = app;
134 ls->logger_data = logger_data; 162 ls->logger_data = logger_data;
135 ls->log_error = log_error; 163 ls->log_error = log_error;
136 ls->log_debug = log_debug; 164 ls->log_debug = log_debug;
139 uw_app_init(app); 167 uw_app_init(app);
140 168
141 { 169 {
142 pthread_t thread; 170 pthread_t thread;
143 171
144 if (uw_time_max && pthread_create(&thread, NULL, ticker, NULL)) { 172 if (uw_time_max && pthread_create_big(&thread, NULL, ticker, NULL)) {
145 fprintf(stderr, "Error creating ticker thread\n"); 173 fprintf(stderr, "Error creating ticker thread\n");
146 exit(1); 174 exit(1);
147 } 175 }
148 } 176 }
149 177
172 periodic *arg = malloc(sizeof(periodic)); 200 periodic *arg = malloc(sizeof(periodic));
173 arg->id = id++; 201 arg->id = id++;
174 arg->ls = ls; 202 arg->ls = ls;
175 arg->pdic = *ps; 203 arg->pdic = *ps;
176 204
177 if (pthread_create(&thread, NULL, periodic_loop, arg)) { 205 if (pthread_create_big(&thread, NULL, periodic_loop, arg)) {
178 fprintf(stderr, "Error creating periodic thread\n"); 206 fprintf(stderr, "Error creating periodic thread\n");
179 exit(1); 207 exit(1);
180 } 208 }
181 } 209 }
182 } 210 }