Commit 56009336 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 f0363b92
......@@ -25,9 +25,7 @@ process and thread control primitives
Created 9/8/1995 Heikki Tuuri
*******************************************************/
#ifndef os0thread_h
#define os0thread_h
#pragma once
#include "univ.i"
/* Possible fixed priorities for threads */
......@@ -66,15 +64,9 @@ typedef void* (*os_posix_f_t) (void*);
typedef unsigned int mysql_pfs_key_t;
#endif /* HAVE_PSI_INTERFACE */
#ifndef _WIN32
#define os_thread_eq(a,b) pthread_equal(a, b)
#define os_thread_yield() sched_yield()
#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
#define os_thread_eq(a,b) IF_WIN(a == b, pthread_equal(a, b))
#define os_thread_yield() IF_WIN(SwitchToThread(), sched_yield())
#define os_thread_get_curr_id() IF_WIN(GetCurrentThreadId(), pthread_self())
/****************************************************************//**
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);
/** Detach and terminate the current thread. */
ATTRIBUTE_NORETURN void os_thread_exit();
/*****************************************************************//**
The thread sleeps at least the time given in microseconds. */
void
os_thread_sleep(
/*============*/
ulint tm); /*!< in: time in microseconds */
#ifdef _WIN32
# define os_thread_sleep(usec) Sleep((DWORD) usec / 1000)
#else
/** Sleep for some time */
void os_thread_sleep(ulint usec);
#endif
......@@ -27,12 +27,6 @@ Created 9/8/1995 Heikki Tuuri
#include "univ.i"
#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
the function given.
......@@ -104,28 +98,24 @@ ATTRIBUTE_NORETURN void os_thread_exit()
#endif
}
/*****************************************************************//**
The thread sleeps at least the time given in microseconds. */
void
os_thread_sleep(
/*============*/
ulint tm) /*!< in: time in microseconds */
#ifndef _WIN32
/** Sleep for some time */
void os_thread_sleep(ulint tm)
{
#ifdef _WIN32
Sleep((DWORD) tm / 1000);
#elif defined(HAVE_NANOSLEEP)
# ifdef HAVE_NANOSLEEP
struct timespec t;
t.tv_sec = tm / 1000000;
t.tv_nsec = (tm % 1000000) * 1000;
::nanosleep(&t, NULL);
#else
# else
struct timeval t;
t.tv_sec = tm / 1000000;
t.tv_usec = tm % 1000000;
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