mirror of
https://github.com/lammertb/libhttp.git
synced 2025-08-09 03:22:45 +03:00
Made httplib_pthread_cond_init global
This commit is contained in:
5
Makefile
5
Makefile
@@ -374,7 +374,7 @@ OBJLIST = \
|
||||
${OBJDIR}win32_clock_gettime${OBJEXT} \
|
||||
${OBJDIR}win32_pthread_cond_broadcast${OBJEXT} \
|
||||
${OBJDIR}win32_pthread_cond_destroy${OBJEXT} \
|
||||
${OBJDIR}win32_pthread_cond_init${OBJEXT} \
|
||||
${OBJDIR}httplib_pthread_cond_init${OBJEXT} \
|
||||
${OBJDIR}httplib_pthread_cond_signal${OBJEXT} \
|
||||
${OBJDIR}httplib_pthread_cond_timedwait${OBJEXT} \
|
||||
${OBJDIR}httplib_pthread_cond_wait${OBJEXT} \
|
||||
@@ -1401,8 +1401,7 @@ ${OBJDIR}win32_pthread_cond_destroy${OBJEXT} : ${SRCDIR}win32_pthread_cond_de
|
||||
${SRCDIR}httplib_main.h \
|
||||
${INCDIR}libhttp.h
|
||||
|
||||
${OBJDIR}win32_pthread_cond_init${OBJEXT} : ${SRCDIR}win32_pthread_cond_init.c \
|
||||
${SRCDIR}httplib_pthread.h \
|
||||
${OBJDIR}httplib_pthread_cond_init${OBJEXT} : ${SRCDIR}httplib_pthread_cond_init.c \
|
||||
${SRCDIR}httplib_main.h \
|
||||
${INCDIR}libhttp.h
|
||||
|
||||
|
29
doc/api/httplib_pthread_cond_init.md
Normal file
29
doc/api/httplib_pthread_cond_init.md
Normal file
@@ -0,0 +1,29 @@
|
||||
# LibHTTP API Reference
|
||||
|
||||
### `httplib_pthread_cond_init( cv, attr );`
|
||||
|
||||
### Parameters
|
||||
|
||||
| Parameter | Type | Description |
|
||||
| :--- | :--- | :--- |
|
||||
|**`cv`**|`pthread_cond_t *`|Storage for the condition variable when the function is successful|
|
||||
|**`attr`**|`const pthread_condattr_t *`|Optional attributes for creating the condition variable|
|
||||
|
||||
|
||||
### Return Value
|
||||
|
||||
| Type | Description |
|
||||
| :--- | :--- |
|
||||
|`int`|Integer value with a success or error code of the function call|
|
||||
|
||||
### Description
|
||||
|
||||
The platform independent function `htptlib_pthread_cond_init()` allocates a condition variable which can be used for letting threads wait for a specific condition. The variable is returned in a location pointed to by a parameter. If the function is successful the value **0** is returned. Otherwise the function returns an error code. On systems which support it, the functionality is implemented as a direct call to `pthrea_cond_init()`. Otherwise own code is used which emulates the same behaviour. Please note that the `attr` parameter is ignored when the function is used on Windows.
|
||||
|
||||
### See Also
|
||||
|
||||
* [`httplib_pthread_cond_broadcast();`](httplib_pthread_cond_broadcast.md)
|
||||
* [`httplib_pthread_cond_destroy();`](httplib_pthread_cond_destroy.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)
|
@@ -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_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 );
|
||||
LIBHTTP_API int httplib_pthread_cond_wait( pthread_cond_t *cv, pthread_mutex_t *mutex );
|
||||
|
@@ -107,23 +107,27 @@ void *event_create(void) {
|
||||
XX_httplib_free(ret);
|
||||
return NULL;
|
||||
}
|
||||
if (0 != pthread_cond_init(&(ret->cond), NULL)) {
|
||||
if (0 != httplib_pthread_cond_init( & ret->cond, NULL)) {
|
||||
/* pthread cond not available */
|
||||
httplib_pthread_mutex_destroy( & ret->mutex );
|
||||
XX_httplib_free(ret);
|
||||
return NULL;
|
||||
}
|
||||
return (void *)ret;
|
||||
return ret;
|
||||
|
||||
} /* event_create */
|
||||
|
||||
|
||||
int event_wait(void *eventhdl) {
|
||||
int event_wait( void *eventhdl ) {
|
||||
|
||||
struct posix_event *ev = (struct posix_event *)eventhdl;
|
||||
httplib_pthread_mutex_lock( & ev->mutex );
|
||||
struct posix_event *ev;
|
||||
|
||||
ev = eventhdl;
|
||||
|
||||
httplib_pthread_mutex_lock( & ev->mutex );
|
||||
httplib_pthread_cond_wait( & ev->cond, & ev->mutex );
|
||||
httplib_pthread_mutex_unlock( & ev->mutex );
|
||||
httplib_pthread_mutex_unlock( & ev->mutex );
|
||||
|
||||
return 1;
|
||||
|
||||
} /* event_wait */
|
||||
|
@@ -32,6 +32,5 @@ 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 pthread_condattr_t *attr );
|
||||
|
||||
#endif /* _WIN32 */
|
||||
|
@@ -22,16 +22,30 @@
|
||||
* THE SOFTWARE.
|
||||
*
|
||||
* ============
|
||||
* Release: 1.8
|
||||
* Release: 2.0
|
||||
*/
|
||||
|
||||
#include "httplib_main.h"
|
||||
#include "httplib_pthread.h"
|
||||
|
||||
/*
|
||||
* int httplib_pthread_cond_init( pthread_cond_t *cv, const pthread_condattr_t *attr );
|
||||
*
|
||||
* The platform independent function httplib_pthread_cond_init() can be used to
|
||||
* create a new condition variable with the attributes as specificied by a
|
||||
* parameter. The function returns 0 when successful and an error code if a
|
||||
* problem occurs.
|
||||
*
|
||||
* On systems which support it, the function is a wrapper arounnd the function
|
||||
* pthread_cond_init(), otherwise equivalent functionality is implemented in
|
||||
* own code.
|
||||
*
|
||||
* Please note that the attr parameter is ignored in the Windows implementation
|
||||
*/
|
||||
|
||||
int httplib_pthread_cond_init( pthread_cond_t *cv, const pthread_condattr_t *attr ) {
|
||||
|
||||
#if defined(_WIN32)
|
||||
|
||||
int pthread_cond_init( pthread_cond_t *cv, const void *attr ) {
|
||||
|
||||
UNUSED_PARAMETER(attr);
|
||||
|
||||
InitializeCriticalSection( & cv->threadIdSec );
|
||||
@@ -39,6 +53,10 @@ int pthread_cond_init( pthread_cond_t *cv, const void *attr ) {
|
||||
|
||||
return 0;
|
||||
|
||||
} /* pthread_cond_init */
|
||||
#else /* _WIN32 */
|
||||
|
||||
#endif /* _WIN32 */
|
||||
return pthread_cond_init( cv, attr );
|
||||
|
||||
#endif /* _WIN32 */
|
||||
|
||||
} /* httplib_pthread_cond_init */
|
@@ -99,8 +99,8 @@ struct httplib_context *httplib_start( const struct httplib_callbacks *callbacks
|
||||
|
||||
ok = 0 == pthread_mutex_init( & ctx->thread_mutex, &XX_httplib_pthread_mutex_attr );
|
||||
#if !defined(ALTERNATIVE_QUEUE)
|
||||
ok &= 0 == pthread_cond_init( & ctx->sq_empty, NULL );
|
||||
ok &= 0 == pthread_cond_init( & ctx->sq_full, NULL );
|
||||
ok &= 0 == httplib_pthread_cond_init( & ctx->sq_empty, NULL );
|
||||
ok &= 0 == httplib_pthread_cond_init( & ctx->sq_full, NULL );
|
||||
#endif
|
||||
ok &= 0 == pthread_mutex_init( & ctx->nonce_mutex, & XX_httplib_pthread_mutex_attr );
|
||||
if ( ! ok ) {
|
||||
|
Reference in New Issue
Block a user