Commit 9d5c1579 authored by Harris Hancock's avatar Harris Hancock

Use std::atomic sentWake in async-win32.{h,c++}

We could also port this by using the deprecated MSVC compiler intrinsics,
but:

1) They're deprecated,
2) I've never used them,
3) We'd need to sprinkle some #if's in the code to support both MinGW and
MSVC, increasing the maintenance burden.
parent 3a02012a
......@@ -27,6 +27,7 @@
#include "async-win32.h"
#include "debug.h"
#include <atomic>
#include <chrono>
#include "refcount.h"
......@@ -176,8 +177,8 @@ bool Win32IocpEventPort::poll() {
}
void Win32IocpEventPort::wake() const {
if (!__atomic_load_n(&sentWake, __ATOMIC_ACQUIRE)) {
__atomic_store_n(&sentWake, true, __ATOMIC_RELEASE);
if (!sentWake.load(std::memory_order_acquire)) {
sentWake.store(true, std::memory_order_release);
KJ_WIN32(PostQueuedCompletionStatus(iocp, 0, 0, nullptr));
}
}
......@@ -212,8 +213,8 @@ void Win32IocpEventPort::waitIocp(DWORD timeoutMs) {
}
bool Win32IocpEventPort::receivedWake() {
if (__atomic_load_n(&sentWake, __ATOMIC_ACQUIRE)) {
__atomic_store_n(&sentWake, false, __ATOMIC_RELEASE);
if (sentWake.load(std::memory_order_acquire)) {
sentWake.store(false, std::memory_order_release);
return true;
} else {
return false;
......
......@@ -29,6 +29,7 @@
#include "async.h"
#include "time.h"
#include "io.h"
#include <atomic>
#include <inttypes.h>
// Include windows.h as lean as possible. (If you need more of the Windows API for your app,
......@@ -200,7 +201,7 @@ private:
AutoCloseHandle thread;
Win32WaitObjectThreadPool waitThreads;
TimerImpl timerImpl;
mutable bool sentWake = false;
mutable std::atomic<bool> sentWake {false};
static TimePoint readClock();
......
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