mirror of
https://github.com/lammertb/libhttp.git
synced 2025-08-07 16:02:55 +03:00
Made httplib_pthread_getspecific global
This commit is contained in:
5
Makefile
5
Makefile
@@ -378,7 +378,7 @@ OBJLIST = \
|
||||
${OBJDIR}win32_pthread_cond_signal${OBJEXT} \
|
||||
${OBJDIR}win32_pthread_cond_timedwait${OBJEXT} \
|
||||
${OBJDIR}win32_pthread_cond_wait${OBJEXT} \
|
||||
${OBJDIR}win32_pthread_getspecific${OBJEXT} \
|
||||
${OBJDIR}httplib_pthread_getspecific${OBJEXT} \
|
||||
${OBJDIR}httplib_pthread_key_create${OBJEXT} \
|
||||
${OBJDIR}httplib_pthread_key_delete${OBJEXT} \
|
||||
${OBJDIR}httplib_pthread_mutex_destroy${OBJEXT} \
|
||||
@@ -1421,8 +1421,7 @@ ${OBJDIR}win32_pthread_cond_wait${OBJEXT} : ${SRCDIR}win32_pthread_cond_wait.
|
||||
${SRCDIR}httplib_main.h \
|
||||
${INCDIR}libhttp.h
|
||||
|
||||
${OBJDIR}win32_pthread_getspecific${OBJEXT} : ${SRCDIR}win32_pthread_getspecific.c \
|
||||
${SRCDIR}httplib_pthread.h \
|
||||
${OBJDIR}httplib_pthread_getspecific${OBJEXT} : ${SRCDIR}httplib_pthread_getspecific.c \
|
||||
${SRCDIR}httplib_main.h \
|
||||
${INCDIR}libhttp.h
|
||||
|
||||
|
26
doc/api/httplib_pthread_getspecific.md
Normal file
26
doc/api/httplib_pthread_getspecific.md
Normal file
@@ -0,0 +1,26 @@
|
||||
# LibHTTP API Reference
|
||||
|
||||
### `httplib_pthread_getspecific( key );`
|
||||
|
||||
### Parameters
|
||||
|
||||
| Parameter | Type | Description |
|
||||
| :--- | :--- | :--- |
|
||||
|**`key`**|`pthread_key_t`|The key of the variable to retrieve|
|
||||
|
||||
### Return Value
|
||||
|
||||
| Type | Description |
|
||||
| :--- | :--- |
|
||||
|`void *`|Pointer to the memory area or NULL of no area could be found|
|
||||
|
||||
### Description
|
||||
|
||||
The platform independent function `httplib_pthread_getspecific()` is used to retrieve a memory area for a thread registered previously with a call to [`httplib_pthread_setspecific()`](httplib_pthread_setspecific.md). If no area could be found, the value `NULL` is returned instead. On systems which support it, the functionality is implemented as a direct call to `pthread_setspecific()`. On other systems own code is used to emulate the same behaviour.
|
||||
|
||||
### See Also
|
||||
|
||||
* [`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_setspecific();`](httplib_pthread_setspecific.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 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 );
|
||||
LIBHTTP_API int httplib_pthread_mutex_destroy( pthread_mutex_t *mutex );
|
||||
|
@@ -37,6 +37,4 @@ 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 );
|
||||
|
||||
void * pthread_getspecific( pthread_key_t key );
|
||||
|
||||
#endif /* _WIN32 */
|
||||
|
@@ -22,18 +22,34 @@
|
||||
* THE SOFTWARE.
|
||||
*
|
||||
* ============
|
||||
* Release: 1.8
|
||||
* Release: 2.0
|
||||
*/
|
||||
|
||||
#include "httplib_main.h"
|
||||
#include "httplib_pthread.h"
|
||||
|
||||
/*
|
||||
* void *httplib_pthread_getspecific( pthread_key_t key );
|
||||
*
|
||||
* Thei platform independent function httplib_pthread_getspecific() returns
|
||||
* data registered for a specific thread with a call to the function
|
||||
* httplib_pthread_setspecific(). If no data could be found the value NULL is
|
||||
* returned.
|
||||
*
|
||||
* If supported by the platform, the function is implemented as a wrapper
|
||||
* around the pthread_getspecific() function. On other platforms equivalent
|
||||
* code for that system is used.
|
||||
*/
|
||||
|
||||
void *httplib_pthread_getspecific( pthread_key_t key ) {
|
||||
|
||||
#if defined(_WIN32)
|
||||
|
||||
void * pthread_getspecific(pthread_key_t key) {
|
||||
|
||||
return TlsGetValue( key );
|
||||
|
||||
} /* pthread_getspecific */
|
||||
#else /* _WIN32 */
|
||||
|
||||
return pthread_getspecific( key );
|
||||
|
||||
#endif /* _WIN32 */
|
||||
|
||||
} /* httplib_pthread_getspecific */
|
@@ -60,7 +60,7 @@ unsigned long XX_httplib_ssl_id_callback( void ) {
|
||||
if (sizeof(pthread_t) > sizeof(unsigned long)) {
|
||||
/* This is the problematic case for CRYPTO_set_id_callback:
|
||||
* The OS pthread_t can not be cast to unsigned long. */
|
||||
struct httplib_workerTLS *tls = (struct httplib_workerTLS *)pthread_getspecific(XX_httplib_sTlsKey);
|
||||
struct httplib_workerTLS *tls = httplib_pthread_getspecific( XX_httplib_sTlsKey );
|
||||
if (tls == NULL) {
|
||||
/* SSL called from an unknown thread: Create some thread index.
|
||||
*/
|
||||
|
@@ -40,7 +40,7 @@
|
||||
void XX_httplib_tls_dtor( void *key ) {
|
||||
|
||||
struct httplib_workerTLS *tls = (struct httplib_workerTLS *)key;
|
||||
/* key == pthread_getspecific( XX_httplib_sTlsKey ); */
|
||||
/* key == httplib_pthread_getspecific( XX_httplib_sTlsKey ); */
|
||||
|
||||
if ( tls != NULL ) {
|
||||
|
||||
|
Reference in New Issue
Block a user