Avoid including windows.h in threads.h

master
Chris Robinson 2020-06-28 12:48:41 -07:00
parent 31791c9997
commit f81558c948
3 changed files with 14 additions and 9 deletions

View File

@ -22,6 +22,11 @@
#include "version.h"
#ifdef _WIN32
#define WIN32_LEAN_AND_MEAN
#include <windows.h>
#endif
#include <exception>
#include <algorithm>
#include <array>

View File

@ -20,12 +20,15 @@
#include "config.h"
#include "opthelpers.h"
#include "threads.h"
#include <system_error>
#ifdef _WIN32
#define WIN32_LEAN_AND_MEAN
#include <windows.h>
#include <limits>
@ -73,15 +76,15 @@ semaphore::~semaphore()
void semaphore::post()
{
if(!ReleaseSemaphore(mSem, 1, nullptr))
if UNLIKELY(!ReleaseSemaphore(static_cast<HANDLE>(mSem), 1, nullptr))
throw std::system_error(std::make_error_code(std::errc::value_too_large));
}
void semaphore::wait() noexcept
{ WaitForSingleObject(mSem, INFINITE); }
{ WaitForSingleObject(static_cast<HANDLE>(mSem), INFINITE); }
bool semaphore::try_wait() noexcept
{ return WaitForSingleObject(mSem, 0) == WAIT_OBJECT_0; }
{ return WaitForSingleObject(static_cast<HANDLE>(mSem), 0) == WAIT_OBJECT_0; }
} // namespace al

View File

@ -11,12 +11,9 @@
#define FORCE_ALIGN
#endif
#ifdef _WIN32
#define WIN32_LEAN_AND_MEAN
#include <windows.h>
#elif defined(__APPLE__)
#if defined(__APPLE__)
#include <dispatch/dispatch.h>
#else
#elif !defined(_WIN32)
#include <semaphore.h>
#endif
@ -26,7 +23,7 @@ namespace al {
class semaphore {
#ifdef _WIN32
using native_type = HANDLE;
using native_type = void*;
#elif defined(__APPLE__)
using native_type = dispatch_semaphore_t;
#else