1
0
mirror of https://github.com/lammertb/libhttp.git synced 2025-08-07 16:02:55 +03:00

Made httplib_pthread_key_delete global

This commit is contained in:
Lammert Bies
2016-12-19 17:20:53 +01:00
parent fe598a1e80
commit 799d4dad65
8 changed files with 56 additions and 12 deletions

View File

@@ -380,7 +380,7 @@ OBJLIST = \
${OBJDIR}win32_pthread_cond_wait${OBJEXT} \ ${OBJDIR}win32_pthread_cond_wait${OBJEXT} \
${OBJDIR}win32_pthread_getspecific${OBJEXT} \ ${OBJDIR}win32_pthread_getspecific${OBJEXT} \
${OBJDIR}win32_pthread_key_create${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_destroy${OBJEXT} \
${OBJDIR}httplib_pthread_mutex_init${OBJEXT} \ ${OBJDIR}httplib_pthread_mutex_init${OBJEXT} \
${OBJDIR}httplib_pthread_mutex_lock${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 \ ${SRCDIR}httplib_main.h \
${INCDIR}libhttp.h ${INCDIR}libhttp.h
${OBJDIR}win32_pthread_key_delete${OBJEXT} : ${SRCDIR}win32_pthread_key_delete.c \ ${OBJDIR}httplib_pthread_key_delete${OBJEXT} : ${SRCDIR}httplib_pthread_key_delete.c \
${SRCDIR}httplib_pthread.h \
${SRCDIR}httplib_main.h \ ${SRCDIR}httplib_main.h \
${INCDIR}libhttp.h ${INCDIR}libhttp.h

View File

@@ -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_connection( conn );`](api/httplib_lock_connection.md)
* [`httplib_lock_context( ctx );`](api/httplib_lock_context.md) * [`httplib_lock_context( ctx );`](api/httplib_lock_context.md)
* [`httplib_poll( pfd, nfds, timeout );`](api/httplib_poll.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_destroy( mutex );`](api/httplib_pthread_mutex_destroy.md)
* [`httplib_pthread_mutex_init( mutex, attr );`](api/httplib_pthread_mutex_init.md) * [`httplib_pthread_mutex_init( mutex, attr );`](api/httplib_pthread_mutex_init.md)
* [`httplib_pthread_mutex_lock( mutex );`](api/httplib_pthread_mutex_lock.md) * [`httplib_pthread_mutex_lock( mutex );`](api/httplib_pthread_mutex_lock.md)

View File

@@ -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)

View File

@@ -22,4 +22,6 @@ The platform independent function `httplib_pthread_setspecific()` is used to set
### See Also ### See Also
* [`httplib_pthread_getspecific();`](httplib_pthread_getspecific.md) * [`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) * [`httplib_pthread_self();`](httplib_pthread_self.md)

View File

@@ -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 int httplib_mkdir( const char *path, int mode );
LIBHTTP_API DIR * httplib_opendir( const char *name ); 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_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_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_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_lock( pthread_mutex_t *mutex );

View File

@@ -104,7 +104,7 @@ void XX_httplib_free_context( struct httplib_context *ctx ) {
pthread_mutexattr_destroy(&XX_httplib_pthread_mutex_attr); pthread_mutexattr_destroy(&XX_httplib_pthread_mutex_attr);
#endif #endif
pthread_key_delete(XX_httplib_sTlsKey); httplib_pthread_key_delete( XX_httplib_sTlsKey );
} }
/* deallocate system name string */ /* deallocate system name string */

View File

@@ -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_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_cond_wait( pthread_cond_t *cv, pthread_mutex_t *mutex );
int pthread_key_create( pthread_key_t *key, void (*_ignored)(void *) ); int pthread_key_create( pthread_key_t *key, void (*destructor)(void *) );
int pthread_key_delete( pthread_key_t key );
void * pthread_getspecific( pthread_key_t key ); void * pthread_getspecific( pthread_key_t key );

View File

@@ -22,18 +22,32 @@
* THE SOFTWARE. * THE SOFTWARE.
* *
* ============ * ============
* Release: 1.8 * Release: 2.0
*/ */
#include "httplib_main.h" #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 */ #endif /* _WIN32 */
} /* httplib_pthread_key_delete */