mirror of
https://github.com/lammertb/libhttp.git
synced 2025-08-09 03:22:45 +03:00
Made httplib_pthread_mutex_destroy global
This commit is contained in:
5
Makefile
5
Makefile
@@ -381,7 +381,7 @@ OBJLIST = \
|
|||||||
${OBJDIR}win32_pthread_getspecific${OBJEXT} \
|
${OBJDIR}win32_pthread_getspecific${OBJEXT} \
|
||||||
${OBJDIR}win32_pthread_key_create${OBJEXT} \
|
${OBJDIR}win32_pthread_key_create${OBJEXT} \
|
||||||
${OBJDIR}win32_pthread_key_delete${OBJEXT} \
|
${OBJDIR}win32_pthread_key_delete${OBJEXT} \
|
||||||
${OBJDIR}win32_pthread_mutex_destroy${OBJEXT} \
|
${OBJDIR}httplib_pthread_mutex_destroy${OBJEXT} \
|
||||||
${OBJDIR}httplib_pthread_mutex_init${OBJEXT} \
|
${OBJDIR}httplib_pthread_mutex_init${OBJEXT} \
|
||||||
${OBJDIR}httplib_pthread_mutex_lock${OBJEXT} \
|
${OBJDIR}httplib_pthread_mutex_lock${OBJEXT} \
|
||||||
${OBJDIR}httplib_pthread_mutex_trylock${OBJEXT} \
|
${OBJDIR}httplib_pthread_mutex_trylock${OBJEXT} \
|
||||||
@@ -1436,8 +1436,7 @@ ${OBJDIR}win32_pthread_key_delete${OBJEXT} : ${SRCDIR}win32_pthread_key_delet
|
|||||||
${SRCDIR}httplib_main.h \
|
${SRCDIR}httplib_main.h \
|
||||||
${INCDIR}libhttp.h
|
${INCDIR}libhttp.h
|
||||||
|
|
||||||
${OBJDIR}win32_pthread_mutex_destroy${OBJEXT} : ${SRCDIR}win32_pthread_mutex_destroy.c \
|
${OBJDIR}httplib_pthread_mutex_destroy${OBJEXT} : ${SRCDIR}httplib_pthread_mutex_destroy.c \
|
||||||
${SRCDIR}httplib_pthread.h \
|
|
||||||
${SRCDIR}httplib_main.h \
|
${SRCDIR}httplib_main.h \
|
||||||
${INCDIR}libhttp.h
|
${INCDIR}libhttp.h
|
||||||
|
|
||||||
|
26
doc/api/httplib_pthread_mutex_destroy.md
Normal file
26
doc/api/httplib_pthread_mutex_destroy.md
Normal file
@@ -0,0 +1,26 @@
|
|||||||
|
# LibHTTP API Reference
|
||||||
|
|
||||||
|
### `httplib_pthread_mutex_destroy( mutex );`
|
||||||
|
|
||||||
|
### Parameters
|
||||||
|
|
||||||
|
| Parameter | Type | Description |
|
||||||
|
| :--- | :--- | :--- |
|
||||||
|
|**`mutex`**|`pthread_mutex_t`|The key to the mutex to destroy|
|
||||||
|
|
||||||
|
### Return Value
|
||||||
|
|
||||||
|
| Type | Description |
|
||||||
|
| :--- | :--- |
|
||||||
|
|`int`|Integer value with the result of the function|
|
||||||
|
|
||||||
|
### Description
|
||||||
|
|
||||||
|
The platform independent function `httplib_pthread_mutex_destroy()` destroys a mutex and frees the allocated resources. The function returns **0** if this is successful, or an error code if it fails. If a mutex is locked by another thread the function will return with an error code. On systems which support it, this function is implemented as a wrapper around `pthread_mutex_destroy()`. On other systems own code is used to emulate the same functionality.
|
||||||
|
|
||||||
|
### See Also
|
||||||
|
|
||||||
|
* [`httplib_pthread_mutex_init();`](httplib_pthread_mutex_init.md)
|
||||||
|
* [`httplib_pthread_mutex_lock();`](httplib_pthread_mutex_lock.md)
|
||||||
|
* [`httplib_pthread_mutex_trylock();`](httplib_pthread_mutex_trylock.md)
|
||||||
|
* [`httplib_pthread_mutex_unlock();`](httplib_pthread_mutex_unlock.md)
|
@@ -985,6 +985,7 @@ LIBHTTP_API int httplib_kill( pid_t pid, int sig_num );
|
|||||||
LIBHTTP_API int httplib_mkdir( const char *path, int mode );
|
LIBHTTP_API int httplib_mkdir( const char *path, int mode );
|
||||||
LIBHTTP_API DIR * httplib_opendir( const char *name );
|
LIBHTTP_API DIR * httplib_opendir( const char *name );
|
||||||
LIBHTTP_API int httplib_poll( struct pollfd *pfd, unsigned int nfds, int timeout );
|
LIBHTTP_API int httplib_poll( struct pollfd *pfd, unsigned int nfds, int timeout );
|
||||||
|
LIBHTTP_API int httplib_pthread_mutex_destroy( pthread_mutex_t *mutex );
|
||||||
LIBHTTP_API int httplib_pthread_mutex_init( pthread_mutex_t *mutex, const pthread_mutexattr_t *attr );
|
LIBHTTP_API int httplib_pthread_mutex_init( pthread_mutex_t *mutex, const pthread_mutexattr_t *attr );
|
||||||
LIBHTTP_API int httplib_pthread_mutex_lock( pthread_mutex_t *mutex );
|
LIBHTTP_API int httplib_pthread_mutex_lock( pthread_mutex_t *mutex );
|
||||||
LIBHTTP_API int httplib_pthread_mutex_trylock( pthread_mutex_t *mutex );
|
LIBHTTP_API int httplib_pthread_mutex_trylock( pthread_mutex_t *mutex );
|
||||||
|
@@ -108,7 +108,7 @@ void httplib_close_connection( struct httplib_connection *conn ) {
|
|||||||
|
|
||||||
httplib_free( client_ctx->workerthreadids );
|
httplib_free( client_ctx->workerthreadids );
|
||||||
httplib_free( client_ctx );
|
httplib_free( client_ctx );
|
||||||
pthread_mutex_destroy( & conn->mutex );
|
httplib_pthread_mutex_destroy( & conn->mutex );
|
||||||
httplib_free( conn );
|
httplib_free( conn );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -109,7 +109,7 @@ void *event_create(void) {
|
|||||||
}
|
}
|
||||||
if (0 != pthread_cond_init(&(ret->cond), NULL)) {
|
if (0 != pthread_cond_init(&(ret->cond), NULL)) {
|
||||||
/* pthread cond not available */
|
/* pthread cond not available */
|
||||||
pthread_mutex_destroy(&(ret->mutex));
|
httplib_pthread_mutex_destroy( & ret->mutex );
|
||||||
XX_httplib_free(ret);
|
XX_httplib_free(ret);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
@@ -144,7 +144,7 @@ void event_destroy(void *eventhdl) {
|
|||||||
|
|
||||||
struct posix_event *ev = (struct posix_event *)eventhdl;
|
struct posix_event *ev = (struct posix_event *)eventhdl;
|
||||||
pthread_cond_destroy(&(ev->cond));
|
pthread_cond_destroy(&(ev->cond));
|
||||||
pthread_mutex_destroy(&(ev->mutex));
|
httplib_pthread_mutex_destroy( & ev->mutex );
|
||||||
XX_httplib_free(ev);
|
XX_httplib_free(ev);
|
||||||
|
|
||||||
} /* event_destroy */
|
} /* event_destroy */
|
||||||
|
@@ -50,7 +50,7 @@ void XX_httplib_free_context( struct httplib_context *ctx ) {
|
|||||||
/* All threads exited, no sync is needed. Destroy thread mutex and
|
/* All threads exited, no sync is needed. Destroy thread mutex and
|
||||||
* condvars
|
* condvars
|
||||||
*/
|
*/
|
||||||
pthread_mutex_destroy(&ctx->thread_mutex);
|
httplib_pthread_mutex_destroy( & ctx->thread_mutex );
|
||||||
#if defined(ALTERNATIVE_QUEUE)
|
#if defined(ALTERNATIVE_QUEUE)
|
||||||
XX_httplib_free(ctx->client_socks);
|
XX_httplib_free(ctx->client_socks);
|
||||||
for (i = 0; (unsigned)i < ctx->cfg_worker_threads; i++) {
|
for (i = 0; (unsigned)i < ctx->cfg_worker_threads; i++) {
|
||||||
@@ -63,10 +63,10 @@ void XX_httplib_free_context( struct httplib_context *ctx ) {
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
/* Destroy other context global data structures mutex */
|
/* Destroy other context global data structures mutex */
|
||||||
pthread_mutex_destroy(&ctx->nonce_mutex);
|
httplib_pthread_mutex_destroy( & ctx->nonce_mutex );
|
||||||
|
|
||||||
#if defined(USE_TIMERS)
|
#if defined(USE_TIMERS)
|
||||||
timers_exit(ctx);
|
timers_exit( ctx );
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/* Deallocate config parameters */
|
/* Deallocate config parameters */
|
||||||
|
@@ -40,8 +40,6 @@ int pthread_cond_wait( pthread_cond_t *cv, pthread_mutex_t *mutex );
|
|||||||
int pthread_key_create( pthread_key_t *key, void (*_ignored)(void *) );
|
int pthread_key_create( pthread_key_t *key, void (*_ignored)(void *) );
|
||||||
int pthread_key_delete( pthread_key_t key );
|
int pthread_key_delete( pthread_key_t key );
|
||||||
|
|
||||||
int pthread_mutex_destroy( pthread_mutex_t *mutex );
|
|
||||||
|
|
||||||
void * pthread_getspecific( pthread_key_t key );
|
void * pthread_getspecific( pthread_key_t key );
|
||||||
|
|
||||||
#endif /* _WIN32 */
|
#endif /* _WIN32 */
|
||||||
|
@@ -22,18 +22,31 @@
|
|||||||
* THE SOFTWARE.
|
* THE SOFTWARE.
|
||||||
*
|
*
|
||||||
* ============
|
* ============
|
||||||
* Release: 1.8
|
* Release: 2.0
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "httplib_main.h"
|
#include "httplib_main.h"
|
||||||
#include "httplib_pthread.h"
|
|
||||||
|
/*
|
||||||
|
* int httplib_pthread_mutex_destroy( pthread_mutex_t *mutex );
|
||||||
|
*
|
||||||
|
* The function httplib_pthread_mutex_destroy() provides a platform independent
|
||||||
|
* way to destroy a mutex. The function returns 0 when successful, and a non
|
||||||
|
* zero value if an error occures. On systems which support it the function is
|
||||||
|
* implemented as a wrapper around pthread_mutex_destroy(). On other systems
|
||||||
|
* own code is used with equivalent functionality.
|
||||||
|
*/
|
||||||
|
|
||||||
|
int httplib_pthread_mutex_destroy( pthread_mutex_t *mutex ) {
|
||||||
|
|
||||||
#if defined(_WIN32)
|
#if defined(_WIN32)
|
||||||
|
|
||||||
int pthread_mutex_destroy( pthread_mutex_t *mutex ) {
|
return ( CloseHandle( *mutex ) == 0 ) ? -1 : 0;
|
||||||
|
|
||||||
return ( CloseHandle(*mutex) == 0 ) ? -1 : 0;
|
#else /* _WIN32 */
|
||||||
|
|
||||||
} /* pthread_mutex_destroy */
|
return pthread_mutex_destroy( mutex );
|
||||||
|
|
||||||
#endif /* _WIN32 */
|
#endif /* _WIN32 */
|
||||||
|
|
||||||
|
} /* httplib_pthread_mutex_destroy */
|
@@ -189,7 +189,7 @@ static void timers_exit( struct httplib_context *ctx ) {
|
|||||||
|
|
||||||
if ( ctx->timers != NULL ) {
|
if ( ctx->timers != NULL ) {
|
||||||
|
|
||||||
pthread_mutex_destroy( & ctx->timers->mutex );
|
httplib_pthread_mutex_destroy( & ctx->timers->mutex );
|
||||||
httplib_free( ctx->timers );
|
httplib_free( ctx->timers );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -41,8 +41,9 @@
|
|||||||
#if !defined(NO_SSL)
|
#if !defined(NO_SSL)
|
||||||
void XX_httplib_uninitialize_ssl( struct httplib_context *ctx ) {
|
void XX_httplib_uninitialize_ssl( struct httplib_context *ctx ) {
|
||||||
|
|
||||||
|
UNUSED_PARAMETER(ctx);
|
||||||
|
|
||||||
int i;
|
int i;
|
||||||
(void)ctx;
|
|
||||||
|
|
||||||
if (httplib_atomic_dec(&XX_httplib_cryptolib_users) == 0) {
|
if (httplib_atomic_dec(&XX_httplib_cryptolib_users) == 0) {
|
||||||
|
|
||||||
@@ -60,7 +61,7 @@ void XX_httplib_uninitialize_ssl( struct httplib_context *ctx ) {
|
|||||||
ERR_remove_state(0);
|
ERR_remove_state(0);
|
||||||
|
|
||||||
for (i = 0; i < CRYPTO_num_locks(); i++) {
|
for (i = 0; i < CRYPTO_num_locks(); i++) {
|
||||||
pthread_mutex_destroy(&XX_httplib_ssl_mutexes[i]);
|
httplib_pthread_mutex_destroy( & XX_httplib_ssl_mutexes[i] );
|
||||||
}
|
}
|
||||||
httplib_free( XX_httplib_ssl_mutexes );
|
httplib_free( XX_httplib_ssl_mutexes );
|
||||||
XX_httplib_ssl_mutexes = NULL;
|
XX_httplib_ssl_mutexes = NULL;
|
||||||
|
@@ -154,7 +154,7 @@ static void *worker_thread_run( struct worker_thread_args *thread_args ) {
|
|||||||
#if defined(_WIN32)
|
#if defined(_WIN32)
|
||||||
CloseHandle( tls.pthread_cond_helper_mutex );
|
CloseHandle( tls.pthread_cond_helper_mutex );
|
||||||
#endif
|
#endif
|
||||||
pthread_mutex_destroy( & conn->mutex );
|
httplib_pthread_mutex_destroy( & conn->mutex );
|
||||||
httplib_free( conn );
|
httplib_free( conn );
|
||||||
|
|
||||||
return NULL;
|
return NULL;
|
||||||
|
Reference in New Issue
Block a user