Merge branch 'v0.20.x'

This commit is contained in:
Max Kellermann
2017-12-16 20:50:53 +01:00
105 changed files with 270 additions and 240 deletions

View File

@@ -30,7 +30,7 @@
#ifndef THREAD_COND_HXX
#define THREAD_COND_HXX
#ifdef WIN32
#ifdef _WIN32
#include "WindowsCond.hxx"
class Cond : public WindowsCond {};

View File

@@ -22,7 +22,7 @@
#include "Compiler.h"
#ifdef WIN32
#ifdef _WIN32
#include <windows.h>
#else
#include <pthread.h>
@@ -34,7 +34,7 @@
* debugging code.
*/
class ThreadId {
#ifdef WIN32
#ifdef _WIN32
DWORD id;
#else
pthread_t id;
@@ -46,7 +46,7 @@ public:
*/
ThreadId() noexcept = default;
#ifdef WIN32
#ifdef _WIN32
constexpr ThreadId(DWORD _id) noexcept:id(_id) {}
#else
constexpr ThreadId(pthread_t _id) noexcept:id(_id) {}
@@ -54,7 +54,7 @@ public:
gcc_const
static ThreadId Null() noexcept {
#ifdef WIN32
#ifdef _WIN32
return 0;
#else
static ThreadId null;
@@ -72,7 +72,7 @@ public:
*/
gcc_pure
static const ThreadId GetCurrent() noexcept {
#ifdef WIN32
#ifdef _WIN32
return ::GetCurrentThreadId();
#else
return pthread_self();
@@ -81,7 +81,7 @@ public:
gcc_pure
bool operator==(const ThreadId &other) const noexcept {
#ifdef WIN32
#ifdef _WIN32
return id == other.id;
#else
return pthread_equal(id, other.id);

View File

@@ -32,7 +32,7 @@
#include <mutex>
#ifdef WIN32
#ifdef _WIN32
#include "CriticalSection.hxx"
class Mutex : public CriticalSection {};

View File

@@ -30,7 +30,7 @@ Thread::Start()
{
assert(!IsDefined());
#ifdef WIN32
#ifdef _WIN32
handle = ::CreateThread(nullptr, 0, ThreadProc, this, 0, &id);
if (handle == nullptr)
throw MakeLastError("Failed to create thread");
@@ -61,7 +61,7 @@ Thread::Join() noexcept
assert(IsDefined());
assert(!IsInside());
#ifdef WIN32
#ifdef _WIN32
::WaitForSingleObject(handle, INFINITE);
::CloseHandle(handle);
handle = nullptr;
@@ -74,7 +74,7 @@ Thread::Join() noexcept
inline void
Thread::Run() noexcept
{
#ifndef WIN32
#ifndef _WIN32
#ifndef NDEBUG
/* this works around a race condition that causes an assertion
failure due to IsInside() spuriously returning false right
@@ -91,7 +91,7 @@ Thread::Run() noexcept
#endif
}
#ifdef WIN32
#ifdef _WIN32
DWORD WINAPI
Thread::ThreadProc(LPVOID ctx) noexcept

View File

@@ -24,7 +24,7 @@
#include "util/BindMethod.hxx"
#include "Compiler.h"
#ifdef WIN32
#ifdef _WIN32
#include <windows.h>
#else
#include <pthread.h>
@@ -36,7 +36,7 @@ class Thread {
typedef BoundMethod<void()> Function;
const Function f;
#ifdef WIN32
#ifdef _WIN32
HANDLE handle = nullptr;
DWORD id;
#else
@@ -67,7 +67,7 @@ public:
#endif
bool IsDefined() const noexcept {
#ifdef WIN32
#ifdef _WIN32
return handle != nullptr;
#else
return defined;
@@ -79,7 +79,7 @@ public:
*/
gcc_pure
bool IsInside() const noexcept {
#ifdef WIN32
#ifdef _WIN32
return GetCurrentThreadId() == id;
#else
#ifdef NDEBUG
@@ -96,7 +96,7 @@ public:
private:
void Run() noexcept;
#ifdef WIN32
#ifdef _WIN32
static DWORD WINAPI ThreadProc(LPVOID ctx) noexcept;
#else
static void *ThreadProc(void *ctx) noexcept;

View File

@@ -34,7 +34,7 @@
#include <sched.h>
#include <sys/syscall.h>
#include <unistd.h>
#elif defined(WIN32)
#elif defined(_WIN32)
#include <windows.h>
#endif
@@ -71,7 +71,7 @@ SetThreadIdlePriority() noexcept
ioprio_set_idle();
#elif defined(WIN32)
#elif defined(_WIN32)
SetThreadPriority(GetCurrentThread(), THREAD_PRIORITY_IDLE);
#endif
};