From e6285eed62735b264ab2cb3f07f067ca75f5f0a7 Mon Sep 17 00:00:00 2001 From: Azat Khuzhin Date: Mon, 13 Jan 2020 22:24:54 +0300 Subject: [PATCH] test: move threads created with THREAD_START() to realtime scheduling class too --- test/regress.h | 1 + test/regress_main.c | 11 ++++++++--- test/regress_thread.h | 14 +++++++++----- 3 files changed, 18 insertions(+), 8 deletions(-) diff --git a/test/regress.h b/test/regress.h index 55a2fddb..07a48339 100644 --- a/test/regress.h +++ b/test/regress.h @@ -141,6 +141,7 @@ SSL_CTX *get_ssl_ctx(void); void init_ssl(void); #endif +void thread_setup(pthread_t pthread); void * basic_test_setup(const struct testcase_t *testcase); int basic_test_cleanup(const struct testcase_t *testcase, void *ptr); diff --git a/test/regress_main.c b/test/regress_main.c index 1bf3efc2..31641d68 100644 --- a/test/regress_main.c +++ b/test/regress_main.c @@ -223,6 +223,13 @@ void move_pthread_to_realtime_scheduling_class(pthread_t pthread) exit(1); } } + +void thread_setup(pthread_t pthread) +{ + move_pthread_to_realtime_scheduling_class(pthread); +} +#else +void thread_setup(pthread_t pthread) {} #endif void * @@ -238,9 +245,7 @@ basic_test_setup(const struct testcase_t *testcase) evthread_flags |= EVTHREAD_PTHREAD_PRIO_INHERIT; #endif -#if defined(__APPLE__) - move_pthread_to_realtime_scheduling_class(pthread_self()); -#endif + thread_setup(pthread_self()); #ifndef _WIN32 if (testcase->flags & TT_ENABLE_IOCP_FLAG) diff --git a/test/regress_thread.h b/test/regress_thread.h index db0d8d19..ca79bc5c 100644 --- a/test/regress_thread.h +++ b/test/regress_thread.h @@ -27,22 +27,26 @@ #ifndef REGRESS_THREAD_H_INCLUDED_ #define REGRESS_THREAD_H_INCLUDED_ +#include "regress.h" + #ifdef EVENT__HAVE_PTHREADS #include #define THREAD_T pthread_t #define THREAD_FN void * #define THREAD_RETURN() return (NULL) -#define THREAD_START(threadvar, fn, arg) \ - pthread_create(&(threadvar), NULL, fn, arg) +#define THREAD_START(threadvar, fn, arg) do { \ + if (!pthread_create(&(threadvar), NULL, fn, arg)) \ + thread_setup(threadvar); \ +} while (0) #define THREAD_JOIN(th) pthread_join(th, NULL) #else #define THREAD_T HANDLE #define THREAD_FN unsigned __stdcall #define THREAD_RETURN() return (0) #define THREAD_START(threadvar, fn, arg) do { \ - uintptr_t threadhandle = _beginthreadex(NULL,0,fn,(arg),0,NULL); \ - (threadvar) = (HANDLE) threadhandle; \ - } while (0) + uintptr_t threadhandle = _beginthreadex(NULL,0,fn,(arg),0,NULL); \ + (threadvar) = (HANDLE) threadhandle; \ +} while (0) #define THREAD_JOIN(th) WaitForSingleObject(th, INFINITE) #endif