1
0
Fork 0
mirror of https://github.com/warmcat/libwebsockets.git synced 2025-03-30 00:00:16 +01:00

windows: work well with vcpkg pthreads

This commit is contained in:
Mykola Stryebkov 2021-04-04 18:50:05 +01:00 committed by Andy Green
parent 3c334d4906
commit 0d06d4bad2
6 changed files with 56 additions and 8 deletions

View file

@ -274,7 +274,7 @@ endif()
#endif()
if (WIN32)
set(LWS_MAX_SMP 1)
#set(LWS_MAX_SMP 1)
if (LWS_WITH_PLUGINS)
set(LWS_WITH_LIBUV_INTERNAL 1)
endif()
@ -414,6 +414,7 @@ if (LWS_WITH_PLUGINS OR (LWS_WITH_EVLIB_PLUGINS AND LWS_WITH_EVENT_LIBS))
endif()
if (WIN32 AND NOT LWS_EXT_PTHREAD_LIBRARIES)
set(LWS_MAX_SMP 1)
message("SMD requires pthreads")
set(LWS_WITH_SYS_SMD 0)
endif()

View file

@ -659,7 +659,11 @@ if (LWS_HAVE_PTHREAD_H AND NOT LWS_PLAT_FREERTOS)
#endif
#include <pthread.h>
int main(void) {
#ifdef __PTW32_H
pthread_t th = {0,0};
#else
pthread_t th = 0;
#endif
pthread_setname_np(th, NULL);
return 0;
}" LWS_HAS_PTHREAD_SETNAME_NP)

View file

@ -845,7 +845,13 @@ lws_callback_http_dummy(struct lws *wsi, enum lws_callback_reasons reason,
#if LWS_MAX_SMP > 1
case LWS_CALLBACK_GET_THREAD_ID:
#ifdef __PTW32_H
/* If we use implementation of PThreads for Win that is
* distributed by VCPKG */
return (int)(lws_intptr_t)(pthread_self()).p;
#else
return (int)(lws_intptr_t)pthread_self();
#endif // __PTW32_H
#endif
default:

View file

@ -1250,7 +1250,13 @@ lws_mutex_refcount_init(struct lws_mutex_refcount *mr)
mr->last_lock_reason = NULL;
mr->lock_depth = 0;
mr->metadata = 0;
#ifdef __PTW32_H
/* If we use implementation of PThreads for Win that is
* distributed by VCPKG */
memset(&mr->lock_owner, 0, sizeof(pthread_t));
#else
mr->lock_owner = 0;
#endif
}
void
@ -1272,7 +1278,14 @@ lws_mutex_refcount_lock(struct lws_mutex_refcount *mr, const char *reason)
*
* - it can be false and change to a different tid that is also false
*/
if (mr->lock_owner == pthread_self()) {
#ifdef __PTW32_H
/* If we use implementation of PThreads for Win that is
* distributed by VCPKG */
if (pthread_equal(mr->lock_owner, pthread_self()))
#else
if (mr->lock_owner == pthread_self())
#endif
{
/* atomic because we only change it if we own the lock */
mr->lock_depth++;
return;
@ -1294,15 +1307,27 @@ lws_mutex_refcount_unlock(struct lws_mutex_refcount *mr)
return;
mr->last_lock_reason = "free";
#ifdef __PTW32_H
/* If we use implementation of PThreads for Win that is
* distributed by VCPKG */
memset(&mr->lock_owner, 0, sizeof(pthread_t));
#else
mr->lock_owner = 0;
//lwsl_notice("tid %d: unlock %s\n", mr->tid, mr->last_lock_reason);
#endif
// lwsl_notice("tid %d: unlock %s\n", mr->tid, mr->last_lock_reason);
pthread_mutex_unlock(&mr->lock);
}
void
lws_mutex_refcount_assert_held(struct lws_mutex_refcount *mr)
{
#ifdef __PTW32_H
/* If we use implementation of PThreads for Win that is
* distributed by VCPKG */
assert(pthread_equal(mr->lock_owner, pthread_self()) && mr->lock_depth);
#else
assert(mr->lock_owner == pthread_self() && mr->lock_depth);
#endif
}
#endif /* SMP */

View file

@ -421,11 +421,19 @@ if (GENCERTS)
message("OPENSSL_INPUT_WIN_PATH = ${OPENSSL_INPUT_WIN_PATH}")
message("cmd = \"${OPENSSL_EXECUTABLE}\" req -new -newkey rsa:2048 -days 10000 -nodes -x509 -keyout \"${TEST_SERVER_SSL_KEY}\" -out \"${TEST_SERVER_SSL_CERT}\"")
execute_process(
COMMAND cmd /c type "${OPENSSL_INPUT_WIN_PATH}"
COMMAND "${OPENSSL_EXECUTABLE}" req -new -newkey rsa:2048 -days 10000 -nodes -x509 -keyout "${TEST_SERVER_SSL_KEY}" -out "${TEST_SERVER_SSL_CERT}"
RESULT_VARIABLE OPENSSL_RETURN_CODE
OUTPUT_QUIET ERROR_QUIET)
if(OPENSSL_CONFIG_FILE)
execute_process(
COMMAND cmd /c type "${OPENSSL_INPUT_WIN_PATH}"
COMMAND "${OPENSSL_EXECUTABLE}" req -config ${OPENSSL_CONFIG_FILE} -new -newkey rsa:2048 -days 10000 -nodes -x509 -keyout "${TEST_SERVER_SSL_KEY}" -out "${TEST_SERVER_SSL_CERT}"
RESULT_VARIABLE OPENSSL_RETURN_CODE
OUTPUT_QUIET ERROR_QUIET)
else()
execute_process(
COMMAND cmd /c type "${OPENSSL_INPUT_WIN_PATH}"
COMMAND "${OPENSSL_EXECUTABLE}" req -new -newkey rsa:2048 -days 10000 -nodes -x509 -keyout "${TEST_SERVER_SSL_KEY}" -out "${TEST_SERVER_SSL_CERT}"
RESULT_VARIABLE OPENSSL_RETURN_CODE
OUTPUT_QUIET ERROR_QUIET)
endif()
message("\n")
endif()

View file

@ -110,7 +110,11 @@ lws_openssl_lock_callback(int mode, int type, const char *file, int line)
static unsigned long
lws_openssl_thread_id(void)
{
#ifdef __PTW32_H
return (unsigned long)(intptr_t)(pthread_self()).p;
#else
return (unsigned long)pthread_self();
#endif
}
#endif