AuroraRuntime/Source/Threading/Primitives/AuConditionMutex.NT.hpp

54 lines
1.3 KiB
C++
Raw Normal View History

2021-06-27 21:25:29 +00:00
/***
Copyright (C) 2021 J Reece Wilson (a/k/a "Reece"). All rights reserved.
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
static auto const kFutexBitWake = 256u; // 2^8
static auto const kFutexBitWait = 512u; // 2^9, next byte over
inline HANDLE gKeyedEventHandle { INVALID_HANDLE_VALUE };
// Actually NT5.x
struct NT4Mutex
{
volatile AuUInt32 uWaitCount {}; // yields while bits are high, dec to release one from the semaphore yield
};
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;
auline bool TryLockNoSpin();
#if !defined(AURORA_FORCE_SRW_LOCKS)
NT4Mutex lock_;
#else
SRWLOCK lock_;
#endif
2021-06-27 21:25:29 +00:00
};
using ConditionMutexImpl = Win32ConditionMutex;
}
#endif