diff --git a/Makefile b/Makefile index 59bac782..adeadcaa 100644 --- a/Makefile +++ b/Makefile @@ -373,7 +373,7 @@ OBJLIST = \ ${OBJDIR}osx_clock_gettime${OBJEXT} \ ${OBJDIR}win32_clock_gettime${OBJEXT} \ ${OBJDIR}win32_pthread_cond_broadcast${OBJEXT} \ - ${OBJDIR}win32_pthread_cond_destroy${OBJEXT} \ + ${OBJDIR}httplib_pthread_cond_destroy${OBJEXT} \ ${OBJDIR}httplib_pthread_cond_init${OBJEXT} \ ${OBJDIR}httplib_pthread_cond_signal${OBJEXT} \ ${OBJDIR}httplib_pthread_cond_timedwait${OBJEXT} \ @@ -1396,8 +1396,7 @@ ${OBJDIR}win32_pthread_cond_broadcast${OBJEXT} : ${SRCDIR}win32_pthread_cond_ ${SRCDIR}httplib_main.h \ ${INCDIR}libhttp.h -${OBJDIR}win32_pthread_cond_destroy${OBJEXT} : ${SRCDIR}win32_pthread_cond_destroy.c \ - ${SRCDIR}httplib_pthread.h \ +${OBJDIR}httplib_pthread_cond_destroy${OBJEXT} : ${SRCDIR}httplib_pthread_cond_destroy.c \ ${SRCDIR}httplib_main.h \ ${INCDIR}libhttp.h diff --git a/doc/api/httplib_pthread_cond_destroy.md b/doc/api/httplib_pthread_cond_destroy.md new file mode 100644 index 00000000..80174c14 --- /dev/null +++ b/doc/api/httplib_pthread_cond_destroy.md @@ -0,0 +1,27 @@ +# LibHTTP API Reference + +### `httplib_pthread_cond_destroy( cv );` + +### Parameters + +| Parameter | Type | Description | +| :--- | :--- | :--- | +|**`cv`**|`pthread_cond_t *`|The condition variable to destroy| + +### Return Value + +| Type | Description | +| :--- | :--- | +|`int`|Integer value with a success or error code of the function call| + +### Description + +The platform independent function `httplib_pthread_cond_destroy()` destroys a condition variable previously allocated with a call to [`httplib_pthread_cond_init()`](httplib_pthread_cond_init.md). The function returns **0** when successful and an error code otherwise. On systems which support it, the functionality is implemented as a direct call to `pthread_cond_destroy()`. On other platforms equivalent functionality is implemented with own code. + +### See Also + +* [`httplib_pthread_cond_broadcast();`](httplib_pthread_cond_broadcast.md) +* [`httplib_pthread_cond_init();`](httplib_pthread_cond_init.md) +* [`httplib_pthread_cond_signal();`](httplib_pthread_cond_signal.md) +* [`httplib_pthread_cond_timedwait();`](httplib_pthread_cond_timedwait.md) +* [`httplib_pthread_cond_wait();`](httplib_pthread_cond_wait.md) diff --git a/include/libhttp.h b/include/libhttp.h index fbf6b181..bfe37858 100644 --- a/include/libhttp.h +++ b/include/libhttp.h @@ -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 DIR * httplib_opendir( const char *name ); LIBHTTP_API int httplib_poll( struct pollfd *pfd, unsigned int nfds, int timeout ); +LIBHTTP_API int httplib_pthread_cond_destroy( pthread_cond_t *cv ); LIBHTTP_API int httplib_pthread_cond_init( pthread_cond_t *cv, const pthread_condattr_t *attr ); 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 ); diff --git a/src/httplib_event_queue.c b/src/httplib_event_queue.c index 1369460b..ad639c33 100644 --- a/src/httplib_event_queue.c +++ b/src/httplib_event_queue.c @@ -133,7 +133,7 @@ int event_wait( void *eventhdl ) { } /* event_wait */ -int event_signal(void *eventhdl) { +int event_signal( void *eventhdl ) { struct posix_event *ev; @@ -148,12 +148,16 @@ int event_signal(void *eventhdl) { } /* event_signal */ -void event_destroy(void *eventhdl) { +void event_destroy( void *eventhdl ) { - struct posix_event *ev = (struct posix_event *)eventhdl; - pthread_cond_destroy(&(ev->cond)); + struct posix_event *ev; + + ev = eventhdl; + + httplib_pthread_cond_destroy( & ev->cond ); httplib_pthread_mutex_destroy( & ev->mutex ); - XX_httplib_free(ev); + + XX_httplib_free( ev ); } /* event_destroy */ diff --git a/src/httplib_free_context.c b/src/httplib_free_context.c index 9e512d27..9056b8a2 100644 --- a/src/httplib_free_context.c +++ b/src/httplib_free_context.c @@ -58,8 +58,8 @@ void XX_httplib_free_context( struct httplib_context *ctx ) { } XX_httplib_free(ctx->client_wait_events); #else - pthread_cond_destroy(&ctx->sq_empty); - pthread_cond_destroy(&ctx->sq_full); + httplib_pthread_cond_destroy( & ctx->sq_empty ); + httplib_pthread_cond_destroy( & ctx->sq_full ); #endif /* Destroy other context global data structures mutex */ diff --git a/src/httplib_pthread.h b/src/httplib_pthread.h index 1c52f164..6216373c 100644 --- a/src/httplib_pthread.h +++ b/src/httplib_pthread.h @@ -31,6 +31,5 @@ extern int XX_httplib_thread_idx_max; #if defined(_WIN32) int pthread_cond_broadcast( pthread_cond_t *cv ); -int pthread_cond_destroy( pthread_cond_t *cv ); #endif /* _WIN32 */ diff --git a/src/win32_pthread_cond_destroy.c b/src/httplib_pthread_cond_destroy.c similarity index 60% rename from src/win32_pthread_cond_destroy.c rename to src/httplib_pthread_cond_destroy.c index 48555ead..8852ce8e 100644 --- a/src/win32_pthread_cond_destroy.c +++ b/src/httplib_pthread_cond_destroy.c @@ -22,23 +22,40 @@ * THE SOFTWARE. * * ============ - * Release: 1.8 + * Release: 2.0 */ #include "httplib_main.h" -#include "httplib_pthread.h" + +/* + * int httplib_pthread_cond_destroy( pthread_cond_t *cv ); + * + * The platform indepent function httplib_pthread_cond_destroy() destroys a + * previously allocated condition variable. The function returns 0 when + * successful and an error code otherwise. On system which support it, the + * function is implemented as a wrapper around pthread_cond_destroy(). On other + * systems the functionality is implemented with own code. + */ + +int httplib_pthread_cond_destroy( pthread_cond_t *cv ) { #if defined(_WIN32) -int pthread_cond_destroy( pthread_cond_t *cv ) { + int retval; - EnterCriticalSection(&cv->threadIdSec); - assert(cv->waiting_thread == NULL); - LeaveCriticalSection(&cv->threadIdSec); - DeleteCriticalSection(&cv->threadIdSec); + EnterCriticalSection( & cv->threadIdSec ); - return 0; + retval = ( cv->waiting_thread == NULL ) ? 0 : -1; -} /* pthread_cond_destroy */ + LeaveCriticalSection( & cv->threadIdSec ); + DeleteCriticalSection( & cv->threadIdSec ); -#endif /* _WIN32 */ + return retval; + +#else /* _WIN32 */ + + return pthread_cond_destroy( cv ); + +#endif /* _WIN32 */ + +} /* httplib_pthread_cond_destroy */