diff --git a/doc/APIReference.md b/doc/APIReference.md index 7ed23e18..820d3b81 100644 --- a/doc/APIReference.md +++ b/doc/APIReference.md @@ -106,6 +106,7 @@ LibHTTP is often used as HTTP and HTTPS library inside a larger application. A * [`httplib_pthread_cond_timedwait( cv, mutex, abstime );`](api/httplib_pthread_cond_timedwait.md) * [`httplib_pthread_cond_wait( cv, mutex );`](api/httplib_pthread_cond_wait.md) * [`httplib_pthread_getspecific( key );`](api/httplib_pthread_getspecific.md) +* [`httplib_pthread_join( thread, value_ptr );`](api/httplib_pthread_join.md) * [`httplib_pthread_key_create( key, destructor );`](api/httplib_pthread_key_create.md) * [`httplib_pthread_key_delete( key );`](api/httplib_pthread_key_delete.md) * [`httplib_pthread_mutex_destroy( mutex );`](api/httplib_pthread_mutex_destroy.md) diff --git a/doc/api/httplib_pthread_join.md b/doc/api/httplib_pthread_join.md new file mode 100644 index 00000000..442d91fc --- /dev/null +++ b/doc/api/httplib_pthread_join.md @@ -0,0 +1,30 @@ +# LibHTTP API Reference + +### `httplib_pthread_join( thread, value_ptr );` + +### Parameters + +| Parameter | Type | Description | +| :--- | :--- | :--- | +|**`key`**|`pthread_t`|The ID of the thread to join| +|**`value_ptr`**|`void *`|Optional pointer to location where the terminating thread stored exit information| + +### Return Value + +| Type | Description | +| :--- | :--- | +|`int`|Integer value with the result of the function| + +### Description + +The platform independent function `httplib_pthread_join()` suspends the execution of the current thread and waits until another thread specified as parameter has terminated. The function returns **0** when successful and a non zero error code if something goes wrong. On systems which support it, the functionality is implemented as a direct call to `pthread_join()`. Otherwise own code is used which emulates the same functionality. + +The parameter `value_ptr` is an optional pointer to a location where an exit pointer of the terminated thread is stored. If this parameter is `NULL` no exit information will be sent back. Please note that the `value_ptr` has only be implemented on systems which use a fall-through to `pthread_join()` but is ignored in other implementations. + +### See Also + +* [`httplib_pthread_getspecific();`](httplib_pthread_getspecific.md) +* [`httplib_pthread_key_create();`](httplib_pthread_key_create.md) +* [`httplib_pthread_key_delete();`](httplib_pthread_key_delete.md) +* [`httplib_pthread_self();`](httplib_pthread_self.md) +* [`httplib_pthread_setspecific();`](httplib_pthread_setspecific.md) diff --git a/include/libhttp.h b/include/libhttp.h index 9a750ba7..94801a2b 100644 --- a/include/libhttp.h +++ b/include/libhttp.h @@ -978,6 +978,7 @@ LIBHTTP_API int httplib_pthread_cond_signal( pthread_cond_t *cv ); LIBHTTP_API int httplib_pthread_cond_timedwait( pthread_cond_t *cv, pthread_mutex_t *mutex, const struct timespec *abstime ); LIBHTTP_API int httplib_pthread_cond_wait( pthread_cond_t *cv, pthread_mutex_t *mutex ); LIBHTTP_API void * httplib_pthread_getspecific( pthread_key_t key ); +LIBHTTP_API int httplib_pthread_join( pthread_t thread, void **value_ptr ); LIBHTTP_API int httplib_pthread_key_create( pthread_key_t *key, void (*destructor)(void *) ); LIBHTTP_API int httplib_pthread_key_delete( pthread_key_t key ); LIBHTTP_API int httplib_pthread_mutex_destroy( pthread_mutex_t *mutex ); diff --git a/src/httplib_close_connection.c b/src/httplib_close_connection.c index d9d32e3a..1136df7c 100644 --- a/src/httplib_close_connection.c +++ b/src/httplib_close_connection.c @@ -122,7 +122,7 @@ void httplib_close_connection( struct httplib_connection *conn ) { for (i=0; icfg_worker_threads; i++) { - if ( client_ctx->workerthreadids[i] != 0 ) XX_httplib_join_thread( client_ctx->workerthreadids[i] ); + if ( client_ctx->workerthreadids[i] != 0 ) httplib_pthread_join( client_ctx->workerthreadids[i], NULL ); } httplib_free( client_ctx->workerthreadids ); diff --git a/src/httplib_main.h b/src/httplib_main.h index 072e0a3f..4ea13726 100644 --- a/src/httplib_main.h +++ b/src/httplib_main.h @@ -843,7 +843,6 @@ bool XX_httplib_is_put_or_delete_method( const struct httplib_connection *conn bool XX_httplib_is_valid_http_method( const char *method ); int XX_httplib_is_valid_port( unsigned long port ); bool XX_httplib_is_websocket_protocol( const struct httplib_connection *conn ); -int XX_httplib_join_thread( pthread_t threadid ); void * XX_httplib_load_dll( struct httplib_context *ctx, const char *dll_name, struct ssl_func *sw ); void XX_httplib_log_access( const struct httplib_connection *conn ); int XX_httplib_match_prefix(const char *pattern, size_t pattern_len, const char *str); diff --git a/src/httplib_master_thread.c b/src/httplib_master_thread.c index 66d5daff..5b8d4669 100644 --- a/src/httplib_master_thread.c +++ b/src/httplib_master_thread.c @@ -147,7 +147,7 @@ static void master_thread_run(void *thread_func_param) { workerthreadcount = ctx->cfg_worker_threads; for (i=0; iworkerthreadids[i] != 0 ) XX_httplib_join_thread(ctx->workerthreadids[i]); + if ( ctx->workerthreadids[i] != 0 ) httplib_pthread_join( ctx->workerthreadids[i], NULL ); } #if !defined(NO_SSL) diff --git a/src/httplib_join_thread.c b/src/httplib_pthread_join.c similarity index 100% rename from src/httplib_join_thread.c rename to src/httplib_pthread_join.c diff --git a/src/httplib_stop.c b/src/httplib_stop.c index 05c70913..b105ff21 100644 --- a/src/httplib_stop.c +++ b/src/httplib_stop.c @@ -62,7 +62,7 @@ void httplib_stop( struct httplib_context *ctx ) { while ( ctx->stop_flag != 2 ) httplib_sleep( 10 ); - XX_httplib_join_thread( mt ); + httplib_pthread_join( mt, NULL ); XX_httplib_free_context( ctx ); #if defined(_WIN32)