2021-06-27 21:25:29 +00:00
|
|
|
/***
|
|
|
|
Copyright (C) 2021 J Reece Wilson (a/k/a "Reece"). All rights reserved.
|
|
|
|
|
2023-03-15 00:35:29 +00:00
|
|
|
File: AuConditionMutex.NT.hpp
|
2021-06-27 21:25:29 +00:00
|
|
|
Date: 2021-6-12
|
|
|
|
Author: Reece
|
|
|
|
***/
|
|
|
|
#pragma once
|
|
|
|
|
2022-11-17 07:46:07 +00:00
|
|
|
#include "AuIConditionMutexEx.hpp"
|
2021-06-27 21:25:29 +00:00
|
|
|
|
|
|
|
#if !defined(_AURUNTIME_GENERICCM)
|
|
|
|
namespace Aurora::Threading::Primitives
|
|
|
|
{
|
2023-04-01 08:53:00 +00:00
|
|
|
// Note: these magic numbers are powers of two such that you can use them as add/sub operations
|
|
|
|
// in place of masking.
|
|
|
|
// ie: add = or
|
|
|
|
// sub = and
|
|
|
|
// assuming the bits are unset/set respectively
|
|
|
|
|
2023-07-09 22:33:12 +00:00
|
|
|
static auto const kFutexBitWake = 256u; // 2^8
|
|
|
|
static auto const kFutexBitWait = 512u; // 2^9, next byte over
|
2023-04-23 18:23:10 +00:00
|
|
|
|
2023-03-15 00:35:29 +00:00
|
|
|
|
|
|
|
inline HANDLE gKeyedEventHandle { INVALID_HANDLE_VALUE };
|
|
|
|
|
2023-07-10 12:12:17 +00:00
|
|
|
// Actually NT5.x
|
2023-03-15 00:35:29 +00:00
|
|
|
struct NT4Mutex
|
|
|
|
{
|
2023-03-15 16:06:58 +00:00
|
|
|
volatile AuUInt32 uWaitCount {}; // yields while bits are high, dec to release one from the semaphore yield
|
2023-03-15 00:35:29 +00:00
|
|
|
};
|
|
|
|
|
2023-03-15 16:53:43 +00:00
|
|
|
struct Win32ConditionMutex final : IConditionMutexEx
|
2021-06-27 21:25:29 +00:00
|
|
|
{
|
|
|
|
Win32ConditionMutex();
|
|
|
|
~Win32ConditionMutex();
|
|
|
|
|
2023-03-15 17:54:59 +00:00
|
|
|
auline bool TryLock() override;
|
|
|
|
auline void Lock() override;
|
|
|
|
auline void Unlock() override;
|
2021-06-27 21:25:29 +00:00
|
|
|
AuUInt GetOSHandle() override;
|
|
|
|
|
2023-07-10 12:12:17 +00:00
|
|
|
auline bool TryLockNoSpin();
|
|
|
|
|
2023-03-16 18:25:23 +00:00
|
|
|
#if !defined(AURORA_FORCE_SRW_LOCKS)
|
2023-03-15 00:35:29 +00:00
|
|
|
NT4Mutex lock_;
|
2023-03-16 18:25:23 +00:00
|
|
|
#else
|
|
|
|
SRWLOCK lock_;
|
|
|
|
#endif
|
2021-06-27 21:25:29 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
using ConditionMutexImpl = Win32ConditionMutex;
|
|
|
|
}
|
|
|
|
#endif
|