summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--storage/innobase/include/os0thread.h28
-rw-r--r--storage/innobase/os/os0thread.cc24
2 files changed, 16 insertions, 36 deletions
diff --git a/storage/innobase/include/os0thread.h b/storage/innobase/include/os0thread.h
index ed989045f18..d784f624b07 100644
--- a/storage/innobase/include/os0thread.h
+++ b/storage/innobase/include/os0thread.h
@@ -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
diff --git a/storage/innobase/os/os0thread.cc b/storage/innobase/os/os0thread.cc
index f3533acfaac..cca488dd9d8 100644
--- a/storage/innobase/os/os0thread.cc
+++ b/storage/innobase/os/os0thread.cc
@@ -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 */