|
@@ -2692,7 +2692,7 @@ struct mg_context {
|
|
unsigned int
|
|
unsigned int
|
|
cfg_worker_threads; /* The number of configured worker threads. */
|
|
cfg_worker_threads; /* The number of configured worker threads. */
|
|
pthread_t *worker_threadids; /* The worker thread IDs */
|
|
pthread_t *worker_threadids; /* The worker thread IDs */
|
|
- unsigned long starter_thread_idx; /* thread index which called mg_start */
|
|
|
|
|
|
+ unsigned long starter_thread_idx; /* thread index which called mg_start */
|
|
|
|
|
|
/* Connection to thread dispatching */
|
|
/* Connection to thread dispatching */
|
|
#if defined(ALTERNATIVE_QUEUE)
|
|
#if defined(ALTERNATIVE_QUEUE)
|
|
@@ -13468,8 +13468,8 @@ mg_set_handler_type(struct mg_context *phys_ctx,
|
|
{
|
|
{
|
|
struct mg_handler_info *tmp_rh, **lastref;
|
|
struct mg_handler_info *tmp_rh, **lastref;
|
|
size_t urilen = strlen(uri);
|
|
size_t urilen = strlen(uri);
|
|
- struct mg_workerTLS tls;
|
|
|
|
- int is_tls_set = 0;
|
|
|
|
|
|
+ struct mg_workerTLS tls;
|
|
|
|
+ int is_tls_set = 0;
|
|
|
|
|
|
if (handler_type == WEBSOCKET_HANDLER) {
|
|
if (handler_type == WEBSOCKET_HANDLER) {
|
|
DEBUG_ASSERT(handler == NULL);
|
|
DEBUG_ASSERT(handler == NULL);
|
|
@@ -13526,22 +13526,21 @@ mg_set_handler_type(struct mg_context *phys_ctx,
|
|
return;
|
|
return;
|
|
}
|
|
}
|
|
|
|
|
|
- /* Internal callbacks have their contexts set
|
|
|
|
- * if called from non-related thread, context must be set
|
|
|
|
- * since internal function assumes it exists.
|
|
|
|
- * For an example see how handler_info_wait_unused()
|
|
|
|
- * waits for reference to become zero
|
|
|
|
- */
|
|
|
|
- if (NULL == pthread_getspecific(sTlsKey))
|
|
|
|
- {
|
|
|
|
- is_tls_set = 1;
|
|
|
|
- tls.is_master = -1;
|
|
|
|
- tls.thread_idx = phys_ctx->starter_thread_idx;
|
|
|
|
|
|
+ /* Internal callbacks have their contexts set
|
|
|
|
+ * if called from non-related thread, context must be set
|
|
|
|
+ * since internal function assumes it exists.
|
|
|
|
+ * For an example see how handler_info_wait_unused()
|
|
|
|
+ * waits for reference to become zero
|
|
|
|
+ */
|
|
|
|
+ if (NULL == pthread_getspecific(sTlsKey)) {
|
|
|
|
+ is_tls_set = 1;
|
|
|
|
+ tls.is_master = -1;
|
|
|
|
+ tls.thread_idx = phys_ctx->starter_thread_idx;
|
|
#if defined(_WIN32)
|
|
#if defined(_WIN32)
|
|
- tls.pthread_cond_helper_mutex = NULL;
|
|
|
|
|
|
+ tls.pthread_cond_helper_mutex = NULL;
|
|
#endif
|
|
#endif
|
|
- pthread_setspecific(sTlsKey, &tls);
|
|
|
|
- }
|
|
|
|
|
|
+ pthread_setspecific(sTlsKey, &tls);
|
|
|
|
+ }
|
|
|
|
|
|
mg_lock_context(phys_ctx);
|
|
mg_lock_context(phys_ctx);
|
|
|
|
|
|
@@ -13584,9 +13583,9 @@ mg_set_handler_type(struct mg_context *phys_ctx,
|
|
mg_free(tmp_rh);
|
|
mg_free(tmp_rh);
|
|
}
|
|
}
|
|
mg_unlock_context(phys_ctx);
|
|
mg_unlock_context(phys_ctx);
|
|
- if (is_tls_set) {
|
|
|
|
- pthread_setspecific(sTlsKey, NULL);
|
|
|
|
- }
|
|
|
|
|
|
+ if (is_tls_set) {
|
|
|
|
+ pthread_setspecific(sTlsKey, NULL);
|
|
|
|
+ }
|
|
return;
|
|
return;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
@@ -13597,9 +13596,9 @@ mg_set_handler_type(struct mg_context *phys_ctx,
|
|
/* no handler to set, this was a remove request to a non-existing
|
|
/* no handler to set, this was a remove request to a non-existing
|
|
* handler */
|
|
* handler */
|
|
mg_unlock_context(phys_ctx);
|
|
mg_unlock_context(phys_ctx);
|
|
- if (is_tls_set) {
|
|
|
|
- pthread_setspecific(sTlsKey, NULL);
|
|
|
|
- }
|
|
|
|
|
|
+ if (is_tls_set) {
|
|
|
|
+ pthread_setspecific(sTlsKey, NULL);
|
|
|
|
+ }
|
|
return;
|
|
return;
|
|
}
|
|
}
|
|
|
|
|
|
@@ -13612,9 +13611,9 @@ mg_set_handler_type(struct mg_context *phys_ctx,
|
|
mg_cry_ctx_internal(phys_ctx,
|
|
mg_cry_ctx_internal(phys_ctx,
|
|
"%s",
|
|
"%s",
|
|
"Cannot create new request handler struct, OOM");
|
|
"Cannot create new request handler struct, OOM");
|
|
- if (is_tls_set) {
|
|
|
|
- pthread_setspecific(sTlsKey, NULL);
|
|
|
|
- }
|
|
|
|
|
|
+ if (is_tls_set) {
|
|
|
|
+ pthread_setspecific(sTlsKey, NULL);
|
|
|
|
+ }
|
|
return;
|
|
return;
|
|
}
|
|
}
|
|
tmp_rh->uri = mg_strdup_ctx(uri, phys_ctx);
|
|
tmp_rh->uri = mg_strdup_ctx(uri, phys_ctx);
|
|
@@ -13624,9 +13623,9 @@ mg_set_handler_type(struct mg_context *phys_ctx,
|
|
mg_cry_ctx_internal(phys_ctx,
|
|
mg_cry_ctx_internal(phys_ctx,
|
|
"%s",
|
|
"%s",
|
|
"Cannot create new request handler struct, OOM");
|
|
"Cannot create new request handler struct, OOM");
|
|
- if (is_tls_set) {
|
|
|
|
- pthread_setspecific(sTlsKey, NULL);
|
|
|
|
- }
|
|
|
|
|
|
+ if (is_tls_set) {
|
|
|
|
+ pthread_setspecific(sTlsKey, NULL);
|
|
|
|
+ }
|
|
return;
|
|
return;
|
|
}
|
|
}
|
|
tmp_rh->uri_len = urilen;
|
|
tmp_rh->uri_len = urilen;
|
|
@@ -13636,9 +13635,9 @@ mg_set_handler_type(struct mg_context *phys_ctx,
|
|
mg_unlock_context(phys_ctx);
|
|
mg_unlock_context(phys_ctx);
|
|
mg_free(tmp_rh);
|
|
mg_free(tmp_rh);
|
|
mg_cry_ctx_internal(phys_ctx, "%s", "Cannot init refcount mutex");
|
|
mg_cry_ctx_internal(phys_ctx, "%s", "Cannot init refcount mutex");
|
|
- if (is_tls_set) {
|
|
|
|
- pthread_setspecific(sTlsKey, NULL);
|
|
|
|
- }
|
|
|
|
|
|
+ if (is_tls_set) {
|
|
|
|
+ pthread_setspecific(sTlsKey, NULL);
|
|
|
|
+ }
|
|
return;
|
|
return;
|
|
}
|
|
}
|
|
if (0 != pthread_cond_init(&tmp_rh->refcount_cond, NULL)) {
|
|
if (0 != pthread_cond_init(&tmp_rh->refcount_cond, NULL)) {
|
|
@@ -13646,9 +13645,9 @@ mg_set_handler_type(struct mg_context *phys_ctx,
|
|
pthread_mutex_destroy(&tmp_rh->refcount_mutex);
|
|
pthread_mutex_destroy(&tmp_rh->refcount_mutex);
|
|
mg_free(tmp_rh);
|
|
mg_free(tmp_rh);
|
|
mg_cry_ctx_internal(phys_ctx, "%s", "Cannot init refcount cond");
|
|
mg_cry_ctx_internal(phys_ctx, "%s", "Cannot init refcount cond");
|
|
- if (is_tls_set) {
|
|
|
|
- pthread_setspecific(sTlsKey, NULL);
|
|
|
|
- }
|
|
|
|
|
|
+ if (is_tls_set) {
|
|
|
|
+ pthread_setspecific(sTlsKey, NULL);
|
|
|
|
+ }
|
|
return;
|
|
return;
|
|
}
|
|
}
|
|
tmp_rh->refcount = 0;
|
|
tmp_rh->refcount = 0;
|
|
@@ -13668,9 +13667,9 @@ mg_set_handler_type(struct mg_context *phys_ctx,
|
|
|
|
|
|
*lastref = tmp_rh;
|
|
*lastref = tmp_rh;
|
|
mg_unlock_context(phys_ctx);
|
|
mg_unlock_context(phys_ctx);
|
|
- if (is_tls_set) {
|
|
|
|
- pthread_setspecific(sTlsKey, NULL);
|
|
|
|
- }
|
|
|
|
|
|
+ if (is_tls_set) {
|
|
|
|
+ pthread_setspecific(sTlsKey, NULL);
|
|
|
|
+ }
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
@@ -18956,12 +18955,12 @@ static
|
|
ctx->dd.auth_nonce_mask =
|
|
ctx->dd.auth_nonce_mask =
|
|
(uint64_t)get_random() ^ (uint64_t)(ptrdiff_t)(options);
|
|
(uint64_t)get_random() ^ (uint64_t)(ptrdiff_t)(options);
|
|
|
|
|
|
- /* Save started thread index to reuse in other external API calls
|
|
|
|
- * For the sake of thread synchronization all non-civetweb threads
|
|
|
|
- * can be considered as single external thread */
|
|
|
|
- ctx->starter_thread_idx = (unsigned)mg_atomic_inc(&thread_idx_max);
|
|
|
|
|
|
+ /* Save started thread index to reuse in other external API calls
|
|
|
|
+ * For the sake of thread synchronization all non-civetweb threads
|
|
|
|
+ * can be considered as single external thread */
|
|
|
|
+ ctx->starter_thread_idx = (unsigned)mg_atomic_inc(&thread_idx_max);
|
|
tls.is_master = -1; /* Thread calling mg_start */
|
|
tls.is_master = -1; /* Thread calling mg_start */
|
|
- tls.thread_idx = ctx->starter_thread_idx;
|
|
|
|
|
|
+ tls.thread_idx = ctx->starter_thread_idx;
|
|
#if defined(_WIN32)
|
|
#if defined(_WIN32)
|
|
tls.pthread_cond_helper_mutex = NULL;
|
|
tls.pthread_cond_helper_mutex = NULL;
|
|
#endif
|
|
#endif
|