mirror of
https://github.com/cuberite/libevent.git
synced 2025-09-15 07:15:03 -04:00
test: fix compilation under win32 (rearrange thread_setup() code)
(cherry picked from commit 34d51e1bc9c650c4d012fe3024f7777c819ba969)
This commit is contained in:
parent
8991346df9
commit
265cbe1077
@ -139,7 +139,6 @@ 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);
|
||||
|
||||
|
@ -81,10 +81,12 @@
|
||||
|
||||
#include "event2/event-config.h"
|
||||
#include "regress.h"
|
||||
#include "regress_thread.h"
|
||||
#include "tinytest.h"
|
||||
#include "tinytest_macros.h"
|
||||
#include "../iocp-internal.h"
|
||||
#include "../event-internal.h"
|
||||
#include "../evthread-internal.h"
|
||||
|
||||
struct evutil_weakrand_state test_weakrand_state;
|
||||
|
||||
@ -186,52 +188,6 @@ ignore_log_cb(int s, const char *msg)
|
||||
{
|
||||
}
|
||||
|
||||
#if defined(__APPLE__)
|
||||
|
||||
#ifdef EVENT__HAVE_MACH_MACH_H
|
||||
#include <mach/mach.h>
|
||||
#endif
|
||||
#ifdef EVENT__HAVE_MACH_MACH_TIME_H
|
||||
#include <mach/mach_time.h>
|
||||
#endif
|
||||
#include <pthread.h>
|
||||
|
||||
/**
|
||||
* Put into the real time scheduling class for better timers latency.
|
||||
* https://developer.apple.com/library/archive/technotes/tn2169/_index.html#//apple_ref/doc/uid/DTS40013172-CH1-TNTAG6000
|
||||
*/
|
||||
void move_pthread_to_realtime_scheduling_class(pthread_t pthread)
|
||||
{
|
||||
mach_timebase_info_data_t timebase_info;
|
||||
mach_timebase_info(&timebase_info);
|
||||
|
||||
const uint64_t NANOS_PER_MSEC = 1000000ULL;
|
||||
double clock2abs = ((double)timebase_info.denom / (double)timebase_info.numer) * NANOS_PER_MSEC;
|
||||
|
||||
thread_time_constraint_policy_data_t policy;
|
||||
policy.period = 0;
|
||||
policy.computation = (uint32_t)(5 * clock2abs); // 5 ms of work
|
||||
policy.constraint = (uint32_t)(10 * clock2abs);
|
||||
policy.preemptible = FALSE;
|
||||
|
||||
int kr = thread_policy_set(pthread_mach_thread_np(pthread_self()),
|
||||
THREAD_TIME_CONSTRAINT_POLICY,
|
||||
(thread_policy_t)&policy,
|
||||
THREAD_TIME_CONSTRAINT_POLICY_COUNT);
|
||||
if (kr != KERN_SUCCESS) {
|
||||
mach_error("thread_policy_set:", kr);
|
||||
exit(1);
|
||||
}
|
||||
}
|
||||
|
||||
void thread_setup(pthread_t pthread)
|
||||
{
|
||||
move_pthread_to_realtime_scheduling_class(pthread);
|
||||
}
|
||||
#else
|
||||
void thread_setup(pthread_t pthread) {}
|
||||
#endif
|
||||
|
||||
void *
|
||||
basic_test_setup(const struct testcase_t *testcase)
|
||||
{
|
||||
@ -239,7 +195,9 @@ basic_test_setup(const struct testcase_t *testcase)
|
||||
evutil_socket_t spair[2] = { -1, -1 };
|
||||
struct basic_test_data *data = NULL;
|
||||
|
||||
thread_setup(pthread_self());
|
||||
#ifndef EVENT__DISABLE_THREAD_SUPPORT
|
||||
thread_setup(THREAD_SELF());
|
||||
#endif
|
||||
|
||||
#ifndef _WIN32
|
||||
if (testcase->flags & TT_ENABLE_IOCP_FLAG)
|
||||
|
@ -66,6 +66,51 @@
|
||||
#include "time-internal.h"
|
||||
#include "regress_thread.h"
|
||||
|
||||
/**
|
||||
* Put into the real time scheduling class for better timers latency.
|
||||
* https://developer.apple.com/library/archive/technotes/tn2169/_index.html#//apple_ref/doc/uid/DTS40013172-CH1-TNTAG6000
|
||||
*/
|
||||
#if defined(__APPLE__)
|
||||
#ifdef EVENT__HAVE_MACH_MACH_H
|
||||
#include <mach/mach.h>
|
||||
#endif
|
||||
#ifdef EVENT__HAVE_MACH_MACH_TIME_H
|
||||
#include <mach/mach_time.h>
|
||||
#endif
|
||||
static void move_pthread_to_realtime_scheduling_class(pthread_t pthread)
|
||||
{
|
||||
mach_timebase_info_data_t info;
|
||||
mach_timebase_info(&info);
|
||||
|
||||
const uint64_t NANOS_PER_MSEC = 1000000ULL;
|
||||
double clock2abs =
|
||||
((double)info.denom / (double)info.numer) * NANOS_PER_MSEC;
|
||||
|
||||
thread_time_constraint_policy_data_t policy;
|
||||
policy.period = 0;
|
||||
policy.computation = (uint32_t)(5 * clock2abs); // 5 ms of work
|
||||
policy.constraint = (uint32_t)(10 * clock2abs);
|
||||
policy.preemptible = FALSE;
|
||||
|
||||
int kr = thread_policy_set(pthread_mach_thread_np(pthread_self()),
|
||||
THREAD_TIME_CONSTRAINT_POLICY,
|
||||
(thread_policy_t)&policy,
|
||||
THREAD_TIME_CONSTRAINT_POLICY_COUNT);
|
||||
if (kr != KERN_SUCCESS) {
|
||||
mach_error("thread_policy_set:", kr);
|
||||
exit(1);
|
||||
}
|
||||
}
|
||||
|
||||
void thread_setup(THREAD_T pthread)
|
||||
{
|
||||
move_pthread_to_realtime_scheduling_class(pthread);
|
||||
}
|
||||
#else /** \__APPLE__ */
|
||||
void thread_setup(THREAD_T pthread) {}
|
||||
#endif /** \!__APPLE__ */
|
||||
|
||||
|
||||
struct cond_wait {
|
||||
void *lock;
|
||||
void *cond;
|
||||
|
@ -34,6 +34,7 @@
|
||||
#define THREAD_T pthread_t
|
||||
#define THREAD_FN void *
|
||||
#define THREAD_RETURN() return (NULL)
|
||||
#define THREAD_SELF() pthread_self()
|
||||
#define THREAD_START(threadvar, fn, arg) do { \
|
||||
if (!pthread_create(&(threadvar), NULL, fn, arg)) \
|
||||
thread_setup(threadvar); \
|
||||
@ -43,11 +44,15 @@
|
||||
#define THREAD_T HANDLE
|
||||
#define THREAD_FN unsigned __stdcall
|
||||
#define THREAD_RETURN() return (0)
|
||||
#define THREAD_START(threadvar, fn, arg) do { \
|
||||
#define THREAD_SELF() GetCurrentThreadId()
|
||||
#define THREAD_START(threadvar, fn, arg) do { \
|
||||
uintptr_t threadhandle = _beginthreadex(NULL,0,fn,(arg),0,NULL); \
|
||||
(threadvar) = (HANDLE) threadhandle; \
|
||||
thread_setup(threadvar); \
|
||||
} while (0)
|
||||
#define THREAD_JOIN(th) WaitForSingleObject(th, INFINITE)
|
||||
#endif
|
||||
|
||||
void thread_setup(THREAD_T pthread);
|
||||
|
||||
#endif
|
||||
|
Loading…
x
Reference in New Issue
Block a user