test: move threads created with THREAD_START() to realtime scheduling class too

This commit is contained in:
Azat Khuzhin 2020-01-13 22:24:54 +03:00
parent b1e46c32db
commit e6285eed62
3 changed files with 18 additions and 8 deletions

View File

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

View File

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

View File

@ -27,22 +27,26 @@
#ifndef REGRESS_THREAD_H_INCLUDED_
#define REGRESS_THREAD_H_INCLUDED_
#include "regress.h"
#ifdef EVENT__HAVE_PTHREADS
#include <pthread.h>
#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