mirror of
https://github.com/lammertb/libhttp.git
synced 2025-08-09 03:22:45 +03:00
Made httplib_pthread_mutex_init global
This commit is contained in:
5
Makefile
5
Makefile
@@ -382,7 +382,7 @@ OBJLIST = \
|
||||
${OBJDIR}win32_pthread_key_create${OBJEXT} \
|
||||
${OBJDIR}win32_pthread_key_delete${OBJEXT} \
|
||||
${OBJDIR}win32_pthread_mutex_destroy${OBJEXT} \
|
||||
${OBJDIR}win32_pthread_mutex_init${OBJEXT} \
|
||||
${OBJDIR}httplib_pthread_mutex_init${OBJEXT} \
|
||||
${OBJDIR}httplib_pthread_mutex_lock${OBJEXT} \
|
||||
${OBJDIR}httplib_pthread_mutex_trylock${OBJEXT} \
|
||||
${OBJDIR}httplib_pthread_mutex_unlock${OBJEXT} \
|
||||
@@ -1441,8 +1441,7 @@ ${OBJDIR}win32_pthread_mutex_destroy${OBJEXT} : ${SRCDIR}win32_pthread_mutex_
|
||||
${SRCDIR}httplib_main.h \
|
||||
${INCDIR}libhttp.h
|
||||
|
||||
${OBJDIR}win32_pthread_mutex_init${OBJEXT} : ${SRCDIR}win32_pthread_mutex_init.c \
|
||||
${SRCDIR}httplib_pthread.h \
|
||||
${OBJDIR}httplib_pthread_mutex_init${OBJEXT} : ${SRCDIR}httplib_pthread_mutex_init.c \
|
||||
${SRCDIR}httplib_main.h \
|
||||
${INCDIR}libhttp.h
|
||||
|
||||
|
29
doc/api/httplib_pthread_mutex_init.md
Normal file
29
doc/api/httplib_pthread_mutex_init.md
Normal file
@@ -0,0 +1,29 @@
|
||||
# LibHTTP API Reference
|
||||
|
||||
### `httplib_pthread_mutex_init( mutex, attr );`
|
||||
|
||||
### Parameters
|
||||
|
||||
| Parameter | Type | Description |
|
||||
| :--- | :--- | :--- |
|
||||
|**`mutex`**|`pthread_mutex_t`|The key to the mutex to initialize|
|
||||
|**`attr`**|`const pthread_mutexattr_t`|Optional attributes for the initialization|
|
||||
|
||||
### Return Value
|
||||
|
||||
| Type | Description |
|
||||
| :--- | :--- |
|
||||
|`int`|Integer value with the result of the function|
|
||||
|
||||
### Description
|
||||
|
||||
The platform independent function `httplib_pthread_mutex_init()` is used to initialize a mutex. The function returns **0** if this is successful, or an error code if it fails. On systems which support it, this function is implemented as a direct call to `pthread_mutex_init()`. On other systems own code is used to emulate the same functionality.
|
||||
|
||||
Please not that on systems which do not support `pthread_mutex_init()` natively that the `attr` parameter is ignored.
|
||||
|
||||
### See Also
|
||||
|
||||
* [`httplib_pthread_mutex_destroy();`](httplib_pthread_mutex_destroy.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 DIR * httplib_opendir( const char *name );
|
||||
LIBHTTP_API int httplib_poll( struct pollfd *pfd, unsigned int nfds, int timeout );
|
||||
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_trylock( pthread_mutex_t *mutex );
|
||||
LIBHTTP_API int httplib_pthread_mutex_unlock( pthread_mutex_t *mutex );
|
||||
|
@@ -102,7 +102,7 @@ void *event_create(void) {
|
||||
struct posix_event *ret = XX_httplib_malloc(sizeof(struct posix_event));
|
||||
if ( ret == NULL ) return NULL;
|
||||
|
||||
if (0 != pthread_mutex_init(&(ret->mutex), NULL)) {
|
||||
if (0 != httplib_pthread_mutex_init( & ret->mutex, NULL ) ) {
|
||||
/* pthread mutex not available */
|
||||
XX_httplib_free(ret);
|
||||
return NULL;
|
||||
|
@@ -41,7 +41,6 @@ int pthread_key_create( pthread_key_t *key, void (*_ignored)(void *) );
|
||||
int pthread_key_delete( pthread_key_t key );
|
||||
|
||||
int pthread_mutex_destroy( pthread_mutex_t *mutex );
|
||||
int pthread_mutex_init( pthread_mutex_t *mutex, void *unused );
|
||||
|
||||
void * pthread_getspecific( pthread_key_t key );
|
||||
|
||||
|
@@ -22,21 +22,34 @@
|
||||
* THE SOFTWARE.
|
||||
*
|
||||
* ============
|
||||
* Release: 1.8
|
||||
* Release: 2.0
|
||||
*/
|
||||
|
||||
#include "httplib_main.h"
|
||||
#include "httplib_pthread.h"
|
||||
|
||||
/*
|
||||
* int httplib_pthread_mutex_init( pthread_mutex_t *mutex, const pthread_mutexattr_t *attr );
|
||||
*
|
||||
* The platform independent function httplib_pthread_mutex_init() is used to
|
||||
* initialize a mutex for future locking. If the function succeeds the value 0
|
||||
* is returned, otherwise an error code. On systems which support it this
|
||||
* function is a wrapper around pthread_mutex_init(). On ither systems own code
|
||||
* is used to emulate equivalent behaviour.
|
||||
*/
|
||||
|
||||
int httplib_pthread_mutex_init( pthread_mutex_t *mutex, const pthread_mutexattr_t *attr ) {
|
||||
|
||||
#if defined(_WIN32)
|
||||
|
||||
int pthread_mutex_init( pthread_mutex_t *mutex, void *unused ) {
|
||||
|
||||
(void)unused;
|
||||
UNUSED_PARAMETER(attr);
|
||||
|
||||
*mutex = CreateMutex( NULL, FALSE, NULL );
|
||||
return (*mutex == NULL) ? -1 : 0;
|
||||
|
||||
} /* pthread_mutex_init */
|
||||
#else /* _WIN32 */
|
||||
|
||||
#endif /* _WIN32 */
|
||||
return pthread_mutex_init( mutex, attr );
|
||||
|
||||
#endif
|
||||
|
||||
} /* httplib_pthread_mutex_init */
|
@@ -176,7 +176,7 @@ static void * timer_thread( void *thread_func_param ) {
|
||||
static int timers_init( struct httplib_context *ctx ) {
|
||||
|
||||
ctx->timers = (struct ttimers *)httplib_calloc(sizeof(struct ttimers), 1);
|
||||
pthread_mutex_init(&ctx->timers->mutex, NULL);
|
||||
httplib_pthread_mutex_init( & ctx->timers->mutex, NULL );
|
||||
|
||||
/* Start timer thread */
|
||||
httplib_start_thread_with_id(timer_thread, ctx, &ctx->timers->threadid);
|
||||
|
Reference in New Issue
Block a user