diff --git a/Makefile b/Makefile index 215398a5..5447186b 100644 --- a/Makefile +++ b/Makefile @@ -380,7 +380,7 @@ OBJLIST = \ ${OBJDIR}win32_pthread_cond_wait${OBJEXT} \ ${OBJDIR}win32_pthread_getspecific${OBJEXT} \ ${OBJDIR}win32_pthread_key_create${OBJEXT} \ - ${OBJDIR}win32_pthread_key_delete${OBJEXT} \ + ${OBJDIR}httplib_pthread_key_delete${OBJEXT} \ ${OBJDIR}httplib_pthread_mutex_destroy${OBJEXT} \ ${OBJDIR}httplib_pthread_mutex_init${OBJEXT} \ ${OBJDIR}httplib_pthread_mutex_lock${OBJEXT} \ @@ -1431,8 +1431,7 @@ ${OBJDIR}win32_pthread_key_create${OBJEXT} : ${SRCDIR}win32_pthread_key_creat ${SRCDIR}httplib_main.h \ ${INCDIR}libhttp.h -${OBJDIR}win32_pthread_key_delete${OBJEXT} : ${SRCDIR}win32_pthread_key_delete.c \ - ${SRCDIR}httplib_pthread.h \ +${OBJDIR}httplib_pthread_key_delete${OBJEXT} : ${SRCDIR}httplib_pthread_key_delete.c \ ${SRCDIR}httplib_main.h \ ${INCDIR}libhttp.h diff --git a/doc/APIReference.md b/doc/APIReference.md index d65013a4..a03b3c20 100644 --- a/doc/APIReference.md +++ b/doc/APIReference.md @@ -100,6 +100,9 @@ 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_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) * [`httplib_pthread_mutex_destroy( mutex );`](api/httplib_pthread_mutex_destroy.md) * [`httplib_pthread_mutex_init( mutex, attr );`](api/httplib_pthread_mutex_init.md) * [`httplib_pthread_mutex_lock( mutex );`](api/httplib_pthread_mutex_lock.md) diff --git a/doc/api/httplib_pthread_key_delete.md b/doc/api/httplib_pthread_key_delete.md new file mode 100644 index 00000000..a6f784eb --- /dev/null +++ b/doc/api/httplib_pthread_key_delete.md @@ -0,0 +1,26 @@ +# LibHTTP API Reference + +### `httplib_pthread_key_delete( key );` + +### Parameters + +| Parameter | Type | Description | +| :--- | :--- | :--- | +|**`key`**|`pthread_key_t`|The key to delete| + +### Return Value + +| Type | Description | +| :--- | :--- | +|`int`|Integer value with the result of the function| + +### Description + +The platform independent function `httplib_pthread_key_delete()` is used to delete a previously allocated key to thread specific data memory. The function returns **0** when succesful or an error code if something went wrong. On systems which support it, the functionality is implemented as a direct call to `pthread_key_delete()`. Otherwise own code is used with equivalent functionality. + +### See Also + +* [`httplib_pthread_getspecific();`](httplib_pthread_getspecific.md) +* [`httplib_pthread_key_create();`](httplib_pthread_key_create.md) +* [`httplib_pthread_self();`](httplib_pthread_self.md) +* [`httplib_pthread_key_setspecific();`](httplib_pthread_setspecific.md) diff --git a/doc/api/httplib_pthread_setspecific.md b/doc/api/httplib_pthread_setspecific.md index ca7f0da0..f2c0021e 100644 --- a/doc/api/httplib_pthread_setspecific.md +++ b/doc/api/httplib_pthread_setspecific.md @@ -22,4 +22,6 @@ The platform independent function `httplib_pthread_setspecific()` is used to set ### See Also * [`httplib_pthread_getspecific();`](httplib_pthread_getspecific.md) +* [`httplib_pthread_key_create();`](httplib_pthread_key_create.md) +* [`httplib_pthread_key_delete();`](httplib_pthread_key_delete.md) * [`httplib_pthread_self();`](httplib_pthread_self.md) diff --git a/include/libhttp.h b/include/libhttp.h index 03fda20b..5e6d6e5b 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_key_delete( pthread_key_t key ); 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_lock( pthread_mutex_t *mutex ); diff --git a/src/httplib_free_context.c b/src/httplib_free_context.c index 291cb373..9e512d27 100644 --- a/src/httplib_free_context.c +++ b/src/httplib_free_context.c @@ -104,7 +104,7 @@ void XX_httplib_free_context( struct httplib_context *ctx ) { pthread_mutexattr_destroy(&XX_httplib_pthread_mutex_attr); #endif - pthread_key_delete(XX_httplib_sTlsKey); + httplib_pthread_key_delete( XX_httplib_sTlsKey ); } /* deallocate system name string */ diff --git a/src/httplib_pthread.h b/src/httplib_pthread.h index c1b9cdfd..4e6542d0 100644 --- a/src/httplib_pthread.h +++ b/src/httplib_pthread.h @@ -37,8 +37,7 @@ 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 ); -int pthread_key_create( pthread_key_t *key, void (*_ignored)(void *) ); -int pthread_key_delete( pthread_key_t key ); +int pthread_key_create( pthread_key_t *key, void (*destructor)(void *) ); void * pthread_getspecific( pthread_key_t key ); diff --git a/src/win32_pthread_key_delete.c b/src/httplib_pthread_key_delete.c similarity index 65% rename from src/win32_pthread_key_delete.c rename to src/httplib_pthread_key_delete.c index b014c044..733ef493 100644 --- a/src/win32_pthread_key_delete.c +++ b/src/httplib_pthread_key_delete.c @@ -22,18 +22,32 @@ * THE SOFTWARE. * * ============ - * Release: 1.8 + * Release: 2.0 */ #include "httplib_main.h" -#include "httplib_pthread.h" -#ifdef _WIN32 +/* + * int httplib_pthread_key_delete( pthread_key_t key ); + * + * The platform independent function httplib_pthread_key_delete() is used to + * delete a previously allocated key which was associated with a thread. The + * function returns 0 when successful and a non zero value if a problem occurs. + * On system which support it, this function is a wrapper around the function + * pthread_key_delete(). On other platforms own code is used to emulate the + * same behaviour. + */ -int pthread_key_delete( pthread_key_t key ) { +int httplib_pthread_key_delete( pthread_key_t key ) { - return TlsFree(key) ? 0 : 1; +#if defined(_WIN32) -} /* pthread_key_delete */ + return TlsFree( key ) ? 0 : 1; + +#else /* _WIN32 */ + + return pthread_key_delete( key ); #endif /* _WIN32 */ + +} /* httplib_pthread_key_delete */