Commit 06efef4b authored by Marko Mäkelä's avatar Marko Mäkelä

MDEV-24308: Windows improvements

This reverts commit e34e53b5
and defines os_thread_sleep() is a macro on Windows.
parent 03ca6495
...@@ -25,9 +25,7 @@ process and thread control primitives ...@@ -25,9 +25,7 @@ process and thread control primitives
Created 9/8/1995 Heikki Tuuri Created 9/8/1995 Heikki Tuuri
*******************************************************/ *******************************************************/
#ifndef os0thread_h #pragma once
#define os0thread_h
#include "univ.i" #include "univ.i"
/* Possible fixed priorities for threads */ /* Possible fixed priorities for threads */
...@@ -66,15 +64,9 @@ typedef void* (*os_posix_f_t) (void*); ...@@ -66,15 +64,9 @@ typedef void* (*os_posix_f_t) (void*);
typedef unsigned int mysql_pfs_key_t; typedef unsigned int mysql_pfs_key_t;
#endif /* HAVE_PSI_INTERFACE */ #endif /* HAVE_PSI_INTERFACE */
#ifndef _WIN32 #define os_thread_eq(a,b) IF_WIN(a == b, pthread_equal(a, b))
#define os_thread_eq(a,b) pthread_equal(a, b) #define os_thread_yield() IF_WIN(SwitchToThread(), sched_yield())
#define os_thread_yield() sched_yield() #define os_thread_get_curr_id() IF_WIN(GetCurrentThreadId(), pthread_self())
#define os_thread_get_curr_id() pthread_self()
#else
bool os_thread_eq(os_thread_id_t a, os_thread_id_t b);
void os_thread_yield();
os_thread_id_t os_thread_get_curr_id();
#endif
/****************************************************************//** /****************************************************************//**
Creates a new thread of execution. The execution starts from Creates a new thread of execution. The execution starts from
...@@ -88,11 +80,9 @@ os_thread_t os_thread_create(os_thread_func_t func, void *arg= nullptr); ...@@ -88,11 +80,9 @@ os_thread_t os_thread_create(os_thread_func_t func, void *arg= nullptr);
/** Detach and terminate the current thread. */ /** Detach and terminate the current thread. */
ATTRIBUTE_NORETURN void os_thread_exit(); ATTRIBUTE_NORETURN void os_thread_exit();
/*****************************************************************//** #ifdef _WIN32
The thread sleeps at least the time given in microseconds. */ # define os_thread_sleep(usec) Sleep((DWORD) usec / 1000)
void #else
os_thread_sleep( /** Sleep for some time */
/*============*/ void os_thread_sleep(ulint usec);
ulint tm); /*!< in: time in microseconds */
#endif #endif
...@@ -27,12 +27,6 @@ Created 9/8/1995 Heikki Tuuri ...@@ -27,12 +27,6 @@ Created 9/8/1995 Heikki Tuuri
#include "univ.i" #include "univ.i"
#include "srv0srv.h" #include "srv0srv.h"
#ifdef _WIN32
bool os_thread_eq(os_thread_id_t a, os_thread_id_t b) { return a == b; }
void os_thread_yield() { SwitchToThread(); }
os_thread_id_t os_thread_get_curr_id() { return GetCurrentThreadId(); }
#endif
/****************************************************************//** /****************************************************************//**
Creates a new thread of execution. The execution starts from Creates a new thread of execution. The execution starts from
the function given. the function given.
...@@ -104,28 +98,24 @@ ATTRIBUTE_NORETURN void os_thread_exit() ...@@ -104,28 +98,24 @@ ATTRIBUTE_NORETURN void os_thread_exit()
#endif #endif
} }
/*****************************************************************//** #ifndef _WIN32
The thread sleeps at least the time given in microseconds. */ /** Sleep for some time */
void void os_thread_sleep(ulint tm)
os_thread_sleep(
/*============*/
ulint tm) /*!< in: time in microseconds */
{ {
#ifdef _WIN32 # ifdef HAVE_NANOSLEEP
Sleep((DWORD) tm / 1000);
#elif defined(HAVE_NANOSLEEP)
struct timespec t; struct timespec t;
t.tv_sec = tm / 1000000; t.tv_sec = tm / 1000000;
t.tv_nsec = (tm % 1000000) * 1000; t.tv_nsec = (tm % 1000000) * 1000;
::nanosleep(&t, NULL); ::nanosleep(&t, NULL);
#else # else
struct timeval t; struct timeval t;
t.tv_sec = tm / 1000000; t.tv_sec = tm / 1000000;
t.tv_usec = tm % 1000000; t.tv_usec = tm % 1000000;
select(0, NULL, NULL, NULL, &t); select(0, NULL, NULL, NULL, &t);
#endif /* _WIN32 */ # endif
} }
#endif /* !_WIN32 */
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment