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

Made httplib_pthread_self global

This commit is contained in:
Lammert Bies
2016-12-19 14:02:32 +01:00
parent 7b5511f89b
commit b67b84dafd
9 changed files with 23 additions and 18 deletions

View File

@@ -386,7 +386,7 @@ OBJLIST = \
${OBJDIR}win32_pthread_mutex_lock${OBJEXT} \ ${OBJDIR}win32_pthread_mutex_lock${OBJEXT} \
${OBJDIR}win32_pthread_mutex_trylock${OBJEXT} \ ${OBJDIR}win32_pthread_mutex_trylock${OBJEXT} \
${OBJDIR}win32_pthread_mutex_unlock${OBJEXT} \ ${OBJDIR}win32_pthread_mutex_unlock${OBJEXT} \
${OBJDIR}win32_pthread_self${OBJEXT} \ ${OBJDIR}httplib_pthread_self${OBJEXT} \
${OBJDIR}win32_pthread_setspecific${OBJEXT} \ ${OBJDIR}win32_pthread_setspecific${OBJEXT} \
${OBJDIR}wince_gmtime${OBJEXT} \ ${OBJDIR}wince_gmtime${OBJEXT} \
${OBJDIR}wince_gmtime_s${OBJEXT} \ ${OBJDIR}wince_gmtime_s${OBJEXT} \
@@ -1461,8 +1461,7 @@ ${OBJDIR}win32_pthread_mutex_unlock${OBJEXT} : ${SRCDIR}win32_pthread_mutex_u
${SRCDIR}httplib_main.h \ ${SRCDIR}httplib_main.h \
${INCDIR}libhttp.h ${INCDIR}libhttp.h
${OBJDIR}win32_pthread_self${OBJEXT} : ${SRCDIR}win32_pthread_self.c \ ${OBJDIR}httplib_pthread_self${OBJEXT} : ${SRCDIR}httplib_pthread_self.c \
${SRCDIR}httplib_pthread.h \
${SRCDIR}httplib_main.h \ ${SRCDIR}httplib_main.h \
${INCDIR}libhttp.h ${INCDIR}libhttp.h

View File

@@ -100,6 +100,7 @@ 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_self();`](api/httplib_pthread_self.md)
* [`httplib_start_thread( f, p );`](api/httplib_start_thread.md) * [`httplib_start_thread( f, p );`](api/httplib_start_thread.md)
* [`httplib_unlock_connection( conn );`](api/httplib_unlock_connection.md) * [`httplib_unlock_connection( conn );`](api/httplib_unlock_connection.md)
* [`httplib_unlock_context( ctx );`](api/httplib_unlock_context.md) * [`httplib_unlock_context( ctx );`](api/httplib_unlock_context.md)

View File

@@ -70,6 +70,8 @@
#define SIGKILL (0) #define SIGKILL (0)
typedef HANDLE pthread_t;
#else /* _WIN32 */ #else /* _WIN32 */
/* /*
@@ -80,6 +82,7 @@
#include <sys/poll.h> #include <sys/poll.h>
#include <sys/types.h> #include <sys/types.h>
#include <dirent.h> #include <dirent.h>
#include <pthread.h>
#include <signal.h> #include <signal.h>
#endif /* _WIN32 */ #endif /* _WIN32 */
@@ -980,6 +983,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 pthread_t httplib_pthread_self( void );
LIBHTTP_API struct dirent * httplib_readdir( DIR *dir ); LIBHTTP_API struct dirent * httplib_readdir( DIR *dir );
LIBHTTP_API int httplib_remove( const char *path ); LIBHTTP_API int httplib_remove( const char *path );
LIBHTTP_API void httplib_set_alloc_callback_func( httplib_alloc_callback_func log_func ); LIBHTTP_API void httplib_set_alloc_callback_func( httplib_alloc_callback_func log_func );

View File

@@ -272,7 +272,6 @@ typedef long off_t;
typedef HANDLE pthread_mutex_t; typedef HANDLE pthread_mutex_t;
typedef DWORD pthread_key_t; typedef DWORD pthread_key_t;
typedef HANDLE pthread_t;
typedef struct { typedef struct {
CRITICAL_SECTION threadIdSec; CRITICAL_SECTION threadIdSec;
struct httplib_workerTLS * waiting_thread; /* The chain of threads */ struct httplib_workerTLS * waiting_thread; /* The chain of threads */

View File

@@ -82,7 +82,7 @@ static void master_thread_run(void *thread_func_param) {
&& ((USE_MASTER_THREAD_PRIORITY) >= min_prio)) { && ((USE_MASTER_THREAD_PRIORITY) >= min_prio)) {
struct sched_param sched_param = {0}; struct sched_param sched_param = {0};
sched_param.sched_priority = (USE_MASTER_THREAD_PRIORITY); sched_param.sched_priority = (USE_MASTER_THREAD_PRIORITY);
pthread_setschedparam(pthread_self(), SCHED_RR, &sched_param); pthread_setschedparam( httplib_pthread_self(), SCHED_RR, & sched_param );
} }
#endif #endif

View File

@@ -48,6 +48,5 @@ int pthread_mutex_unlock( pthread_mutex_t *mutex );
void * pthread_getspecific( pthread_key_t key ); void * pthread_getspecific( pthread_key_t key );
int pthread_setspecific( pthread_key_t key, void *value ); int pthread_setspecific( pthread_key_t key, void *value );
DWORD pthread_self( void );
#endif /* _WIN32 */ #endif /* _WIN32 */

View File

@@ -26,23 +26,26 @@
*/ */
#include "httplib_main.h" #include "httplib_main.h"
#include "httplib_pthread.h"
#ifdef _WIN32
/* /*
* DWORD pthread_self( void ); * pthread_t httplib_pthread_self( void );
* *
* The function pthread_self() returns in ID describing the current thread. On * The function httplib_pthread_self() provides a platform independent way to
* windows where there is no support for the pthread() library, this * retrieve an ID associated with the current thread. On systems which support
* implementation provides a comparable function which can be used as an * it a call to pthread_self() is used. Otherwise a system specific value is
* alternative. * returned which best resembles the functionality of the pthread_ equivalent.
*/ */
DWORD pthread_self( void ) { pthread_t httplib_pthread_self( void ) {
#if defined(_WIN32)
return GetCurrentThreadId(); return GetCurrentThreadId();
} /* pthread_self */ #else /* _WIN32 */
return pthread_self();
#endif /* _WIN32 */ #endif /* _WIN32 */
} /* httplib_pthread_self */

View File

@@ -79,7 +79,7 @@ void XX_httplib_set_thread_name(const char *name) {
#elif defined(__GLIBC__) \ #elif defined(__GLIBC__) \
&& ((__GLIBC__ > 2) || ((__GLIBC__ == 2) && (__GLIBC_MINOR__ >= 12))) && ((__GLIBC__ > 2) || ((__GLIBC__ == 2) && (__GLIBC_MINOR__ >= 12)))
/* pthread_setname_np first appeared in glibc in version 2.12*/ /* pthread_setname_np first appeared in glibc in version 2.12*/
pthread_setname_np(pthread_self(), threadName); pthread_setname_np( httplib_pthread_self(), threadName );
#elif defined(__linux__) #elif defined(__linux__)
/* on linux we can use the old prctl function */ /* on linux we can use the old prctl function */
prctl(PR_SET_NAME, threadName, 0, 0, 0); prctl(PR_SET_NAME, threadName, 0, 0, 0);

View File

@@ -75,7 +75,7 @@ unsigned long XX_httplib_ssl_id_callback( void ) {
* can rise a warning/error, depending on the platform. * can rise a warning/error, depending on the platform.
* Here memcpy is used as an anything-to-anything cast. */ * Here memcpy is used as an anything-to-anything cast. */
unsigned long ret = 0; unsigned long ret = 0;
pthread_t t = pthread_self(); pthread_t t = httplib_pthread_self();
memcpy(&ret, &t, sizeof(pthread_t)); memcpy(&ret, &t, sizeof(pthread_t));
return ret; return ret;
} }