Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
MDEV-24308: Windows improvements
This reverts commit e34e53b
and defines os_thread_sleep() is a macro on Windows.
  • Loading branch information
dr-m committed Dec 3, 2020
1 parent 03ca649 commit 06efef4
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 36 deletions.
28 changes: 9 additions & 19 deletions storage/innobase/include/os0thread.h
Expand Up @@ -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 */
Expand Down Expand Up @@ -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
Expand All @@ -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
24 changes: 7 additions & 17 deletions storage/innobase/os/os0thread.cc
Expand Up @@ -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.
Expand Down Expand Up @@ -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 */

0 comments on commit 06efef4

Please sign in to comment.