|
@@ -6864,7 +6864,7 @@ struct mg_context *mg_start(const struct mg_callbacks *callbacks,
|
|
{
|
|
{
|
|
struct mg_context *ctx;
|
|
struct mg_context *ctx;
|
|
const char *name, *value, *default_value;
|
|
const char *name, *value, *default_value;
|
|
- int i;
|
|
|
|
|
|
+ int i, ok;
|
|
int workerthreadcount;
|
|
int workerthreadcount;
|
|
|
|
|
|
#if defined(_WIN32) && !defined(__SYMBIAN32__)
|
|
#if defined(_WIN32) && !defined(__SYMBIAN32__)
|
|
@@ -6886,6 +6886,7 @@ struct mg_context *mg_start(const struct mg_callbacks *callbacks,
|
|
|
|
|
|
if (sTlsInit==0) {
|
|
if (sTlsInit==0) {
|
|
if (0 != pthread_key_create(&sTlsKey, NULL)) {
|
|
if (0 != pthread_key_create(&sTlsKey, NULL)) {
|
|
|
|
+ /* Fatal error - abort start. However, this situation should never occur in practice. */
|
|
mg_cry(fc(ctx), "Cannot initialize thread local storage");
|
|
mg_cry(fc(ctx), "Cannot initialize thread local storage");
|
|
mg_free(ctx);
|
|
mg_free(ctx);
|
|
return NULL;
|
|
return NULL;
|
|
@@ -6893,6 +6894,18 @@ struct mg_context *mg_start(const struct mg_callbacks *callbacks,
|
|
sTlsInit++;
|
|
sTlsInit++;
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ ok = 0==pthread_mutex_init(&ctx->thread_mutex, NULL);
|
|
|
|
+ ok &= 0==pthread_cond_init(&ctx->thread_cond, NULL);
|
|
|
|
+ ok &= 0==pthread_cond_init(&ctx->sq_empty, NULL);
|
|
|
|
+ ok &= 0==pthread_cond_init(&ctx->sq_full, NULL);
|
|
|
|
+ ok &= 0==pthread_mutex_init(&ctx->nonce_mutex, NULL);
|
|
|
|
+ if (!ok) {
|
|
|
|
+ /* Fatal error - abort start. However, this situation should never occur in practice. */
|
|
|
|
+ mg_cry(fc(ctx), "Cannot initialize thread synchronization objects");
|
|
|
|
+ mg_free(ctx);
|
|
|
|
+ return NULL;
|
|
|
|
+ }
|
|
|
|
+
|
|
if (callbacks) {
|
|
if (callbacks) {
|
|
ctx->callbacks = *callbacks;
|
|
ctx->callbacks = *callbacks;
|
|
}
|
|
}
|
|
@@ -6952,13 +6965,6 @@ struct mg_context *mg_start(const struct mg_callbacks *callbacks,
|
|
(void) signal(SIGPIPE, SIG_IGN);
|
|
(void) signal(SIGPIPE, SIG_IGN);
|
|
#endif /* !_WIN32 && !__SYMBIAN32__ */
|
|
#endif /* !_WIN32 && !__SYMBIAN32__ */
|
|
|
|
|
|
- (void) pthread_mutex_init(&ctx->thread_mutex, NULL);
|
|
|
|
- (void) pthread_cond_init(&ctx->thread_cond, NULL);
|
|
|
|
- (void) pthread_cond_init(&ctx->sq_empty, NULL);
|
|
|
|
- (void) pthread_cond_init(&ctx->sq_full, NULL);
|
|
|
|
-
|
|
|
|
- (void) pthread_mutex_init(&ctx->nonce_mutex, NULL);
|
|
|
|
-
|
|
|
|
workerthreadcount = atoi(ctx->config[NUM_THREADS]);
|
|
workerthreadcount = atoi(ctx->config[NUM_THREADS]);
|
|
|
|
|
|
if (workerthreadcount > MAX_WORKER_THREADS) {
|
|
if (workerthreadcount > MAX_WORKER_THREADS) {
|