mirror of
https://github.com/lammertb/libhttp.git
synced 2025-08-07 16:02:55 +03:00
Made httplib_pthread_cond_wait global
This commit is contained in:
5
Makefile
5
Makefile
@@ -377,7 +377,7 @@ OBJLIST = \
|
||||
${OBJDIR}win32_pthread_cond_init${OBJEXT} \
|
||||
${OBJDIR}win32_pthread_cond_signal${OBJEXT} \
|
||||
${OBJDIR}win32_pthread_cond_timedwait${OBJEXT} \
|
||||
${OBJDIR}win32_pthread_cond_wait${OBJEXT} \
|
||||
${OBJDIR}httplib_pthread_cond_wait${OBJEXT} \
|
||||
${OBJDIR}httplib_pthread_getspecific${OBJEXT} \
|
||||
${OBJDIR}httplib_pthread_key_create${OBJEXT} \
|
||||
${OBJDIR}httplib_pthread_key_delete${OBJEXT} \
|
||||
@@ -1416,8 +1416,7 @@ ${OBJDIR}win32_pthread_cond_timedwait${OBJEXT} : ${SRCDIR}win32_pthread_cond_
|
||||
${SRCDIR}httplib_main.h \
|
||||
${INCDIR}libhttp.h
|
||||
|
||||
${OBJDIR}win32_pthread_cond_wait${OBJEXT} : ${SRCDIR}win32_pthread_cond_wait.c \
|
||||
${SRCDIR}httplib_pthread.h \
|
||||
${OBJDIR}httplib_pthread_cond_wait${OBJEXT} : ${SRCDIR}httplib_pthread_cond_wait.c \
|
||||
${SRCDIR}httplib_main.h \
|
||||
${INCDIR}libhttp.h
|
||||
|
||||
|
@@ -100,6 +100,12 @@ LibHTTP is often used as HTTP and HTTPS library inside a larger application. A
|
||||
* [`httplib_lock_connection( conn );`](api/httplib_lock_connection.md)
|
||||
* [`httplib_lock_context( ctx );`](api/httplib_lock_context.md)
|
||||
* [`httplib_poll( pfd, nfds, timeout );`](api/httplib_poll.md)
|
||||
* [`httplib_pthread_cond_broadcast( cv );`](api/httplib_pthread_cond_broadcast.md)
|
||||
* [`httplib_pthread_cond_destroy( cv );`](api/httplib_pthread_cond_destroy.md)
|
||||
* [`httplib_pthread_cond_init( cv, attr );`](api/httplib_pthread_cond_init.md)
|
||||
* [`httplib_pthread_cond_signal( cv );`](api/httplib_pthread_cond_signal.md)
|
||||
* [`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_getspecific.md)
|
||||
* [`httplib_pthread_key_create( key, destructor );`](api/httplib_key_create.md)
|
||||
* [`httplib_pthread_key_delete( key );`](api/httplib_pthread_key_delete.md)
|
||||
|
28
doc/api/httplib_pthread_cond_wait.md
Normal file
28
doc/api/httplib_pthread_cond_wait.md
Normal file
@@ -0,0 +1,28 @@
|
||||
# LibHTTP API Reference
|
||||
|
||||
### `httplib_pthread_cond_wait( cv, mutex );`
|
||||
|
||||
### Parameters
|
||||
|
||||
| Parameter | Type | Description |
|
||||
| :--- | :--- | :--- |
|
||||
|**`cv`**|`pthread_cond_t`|The condition to wait for|
|
||||
|**`mutex`**|`pthread_mutex_t *`|The mutex to release when the condition is met|
|
||||
|
||||
### 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_wait()` is used to wait for a specific condition to be met. After the condition is met, the specified mutex is unlocked. If the function succeeds, the value **0** is returned, otherwise the return value is an error code. On systems which support it, the functionality is implemented as a direct call to `pthread_cond_wait()`. Otherwise an OS dependent alternative function is called.
|
||||
|
||||
### See Also
|
||||
|
||||
* [`httplib_pthread_cond_broadcast();`](httplib_pthread_cond_broadcast.md)
|
||||
* [`httplib_pthread_cond_destroy();`](httplib_pthread_cond_destroy.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)
|
@@ -985,6 +985,8 @@ 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_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_key_create( pthread_key_t *key, void (*destructor)(void *) );
|
||||
LIBHTTP_API int httplib_pthread_key_delete( pthread_key_t key );
|
||||
|
@@ -60,7 +60,8 @@ int XX_httplib_consume_socket( struct httplib_context *ctx, struct socket *sp, i
|
||||
|
||||
/* If the queue is empty, wait. We're idle at this point. */
|
||||
while (ctx->sq_head == ctx->sq_tail && ctx->stop_flag == 0) {
|
||||
pthread_cond_wait(&ctx->sq_full, &ctx->thread_mutex);
|
||||
|
||||
httplib_pthread_cond_wait( & ctx->sq_full, & ctx->thread_mutex );
|
||||
}
|
||||
|
||||
/* If we're stopping, sq_head may be equal to sq_tail. */
|
||||
|
@@ -122,7 +122,7 @@ int event_wait(void *eventhdl) {
|
||||
|
||||
struct posix_event *ev = (struct posix_event *)eventhdl;
|
||||
httplib_pthread_mutex_lock( & ev->mutex );
|
||||
pthread_cond_wait(&(ev->cond), &(ev->mutex));
|
||||
httplib_pthread_cond_wait( & ev->cond, & ev->mutex );
|
||||
httplib_pthread_mutex_unlock( & ev->mutex );
|
||||
return 1;
|
||||
|
||||
|
@@ -69,7 +69,8 @@ void XX_httplib_produce_socket(struct httplib_context *ctx, const struct socket
|
||||
|
||||
/* If the queue is full, wait */
|
||||
while (ctx->stop_flag == 0 && ctx->sq_head - ctx->sq_tail >= QUEUE_SIZE(ctx)) {
|
||||
pthread_cond_wait(&ctx->sq_empty, &ctx->thread_mutex);
|
||||
|
||||
httplib_pthread_cond_wait( & ctx->sq_empty, & ctx->thread_mutex );
|
||||
}
|
||||
|
||||
if (ctx->sq_head - ctx->sq_tail < QUEUE_SIZE(ctx)) {
|
||||
|
@@ -32,9 +32,8 @@ extern int XX_httplib_thread_idx_max;
|
||||
|
||||
int pthread_cond_broadcast( pthread_cond_t *cv );
|
||||
int pthread_cond_destroy( pthread_cond_t *cv );
|
||||
int pthread_cond_init( pthread_cond_t *cv, const void *unused );
|
||||
int pthread_cond_init( pthread_cond_t *cv, const pthread_condattr_t *attr );
|
||||
int pthread_cond_signal( pthread_cond_t *cv );
|
||||
int pthread_cond_timedwait( pthread_cond_t *cv, pthread_mutex_t *mutex, const struct timespec *abstime );
|
||||
int pthread_cond_wait( pthread_cond_t *cv, pthread_mutex_t *mutex );
|
||||
|
||||
#endif /* _WIN32 */
|
||||
|
@@ -22,18 +22,29 @@
|
||||
* THE SOFTWARE.
|
||||
*
|
||||
* ============
|
||||
* Release: 1.8
|
||||
* Release: 2.0
|
||||
*/
|
||||
|
||||
#include "httplib_main.h"
|
||||
#include "httplib_pthread.h"
|
||||
|
||||
/*
|
||||
* int httplib_pthread_cond_wait( pthread_cond_t *cv, pthread_mutex_t *mutex );
|
||||
*
|
||||
* The function httplib_pthread_cond_wait() performs a wait until a condition
|
||||
* is met and then releases the specified mutex. The function returns 0 on
|
||||
* success and a non zero error code at failure.
|
||||
*/
|
||||
|
||||
int httplib_pthread_cond_wait( pthread_cond_t *cv, pthread_mutex_t *mutex ) {
|
||||
|
||||
#if defined(_WIN32)
|
||||
|
||||
int pthread_cond_wait( pthread_cond_t *cv, pthread_mutex_t *mutex ) {
|
||||
return httplib_pthread_cond_timedwait( cv, mutex, NULL );
|
||||
|
||||
return pthread_cond_timedwait(cv, mutex, NULL);
|
||||
#else /* _WIN32 */
|
||||
|
||||
} /* pthread_cond_wait */
|
||||
return pthread_cond_wait( cv, mutex );
|
||||
|
||||
#endif /* _WIN32 */
|
||||
#endif /* _WIN32 */
|
||||
|
||||
} /* httplib_pthread_cond_wait */
|
Reference in New Issue
Block a user