2021-06-27 21:25:29 +00:00
|
|
|
/***
|
|
|
|
Copyright (C) 2021 J Reece Wilson (a/k/a "Reece"). All rights reserved.
|
|
|
|
|
2023-03-12 15:27:28 +00:00
|
|
|
File: AuSemaphore.NT.hpp
|
2021-06-27 21:25:29 +00:00
|
|
|
Date: 2021-6-12
|
|
|
|
Author: Reece
|
|
|
|
***/
|
|
|
|
#pragma once
|
|
|
|
|
2023-03-15 02:38:26 +00:00
|
|
|
#include "AuConditionMutex.Generic.hpp"
|
|
|
|
#include "AuConditionVariable.NT.hpp"
|
|
|
|
|
2021-06-27 21:25:29 +00:00
|
|
|
namespace Aurora::Threading::Primitives
|
|
|
|
{
|
2023-08-19 10:41:37 +00:00
|
|
|
struct SemaphoreImpl final : ISemaphore
|
2021-06-27 21:25:29 +00:00
|
|
|
{
|
2023-08-18 14:25:54 +00:00
|
|
|
SemaphoreImpl(AuUInt16 uIntialValue = 0);
|
2023-04-23 18:23:10 +00:00
|
|
|
~SemaphoreImpl();
|
2021-06-27 21:25:29 +00:00
|
|
|
|
|
|
|
bool HasOSHandle(AuMach &mach) override;
|
|
|
|
bool HasLockImplementation() override;
|
|
|
|
bool TryLock() override;
|
2023-04-03 07:21:44 +00:00
|
|
|
bool LockMS(AuUInt64 timeout) override;
|
2023-03-12 15:27:28 +00:00
|
|
|
bool LockNS(AuUInt64 timeout) override;
|
2023-08-24 12:55:31 +00:00
|
|
|
bool LockAbsNS(AuUInt64 qwTimeoutAbs) override;
|
2021-06-27 21:25:29 +00:00
|
|
|
void Lock() override;
|
2023-08-18 14:25:54 +00:00
|
|
|
void Unlock(AuUInt16 count) override;
|
2021-06-27 21:25:29 +00:00
|
|
|
void Unlock() override;
|
|
|
|
|
2023-06-26 07:33:47 +00:00
|
|
|
auline bool TryLockNoSpin();
|
2023-08-19 17:14:28 +00:00
|
|
|
auline bool TryLockHeavy();
|
2023-06-26 07:33:47 +00:00
|
|
|
|
2023-08-24 12:55:31 +00:00
|
|
|
auline AuUInt32 *GetSleepCounter();
|
2021-06-27 21:25:29 +00:00
|
|
|
private:
|
2023-09-02 03:55:43 +00:00
|
|
|
AuAUInt32 dwState_ {};
|
2023-08-21 16:34:24 +00:00
|
|
|
ConditionMutexInternal mutex;
|
|
|
|
ConditionVariableInternal var;
|
2021-06-27 21:25:29 +00:00
|
|
|
};
|
|
|
|
}
|