2021-06-27 21:25:29 +00:00
|
|
|
/***
|
2024-01-29 14:09:59 +00:00
|
|
|
Copyright (C) 2021-2024 J Reece Wilson (a/k/a "Reece"). All rights reserved.
|
2021-06-27 21:25:29 +00:00
|
|
|
|
|
|
|
File: Mutex.Generic.hpp
|
|
|
|
Date: 2021-6-12
|
|
|
|
Author: Reece
|
|
|
|
***/
|
|
|
|
#pragma once
|
|
|
|
|
2021-09-06 10:58:08 +00:00
|
|
|
#if defined(AURORA_IS_MODERNNT_DERIVED)
|
2022-11-17 07:46:07 +00:00
|
|
|
#include "AuMutex.NT.hpp"
|
2022-12-28 23:44:45 +00:00
|
|
|
#elif defined(AURORA_IS_LINUX_DERIVED)
|
|
|
|
#include "AuMutex.Linux.hpp"
|
2021-06-27 21:25:29 +00:00
|
|
|
#else
|
2022-12-28 23:44:45 +00:00
|
|
|
#define _AURUNTIME_GENERIC_MUTEX
|
2021-06-27 21:25:29 +00:00
|
|
|
|
|
|
|
namespace Aurora::Threading::Primitives
|
|
|
|
{
|
2023-12-29 15:35:25 +00:00
|
|
|
struct MutexGenericImpl final : IHyperWaitable
|
2021-06-27 21:25:29 +00:00
|
|
|
{
|
2023-12-29 15:35:25 +00:00
|
|
|
MutexGenericImpl();
|
|
|
|
~MutexGenericImpl();
|
2021-06-27 21:25:29 +00:00
|
|
|
|
|
|
|
bool HasOSHandle(AuMach &mach) override;
|
|
|
|
bool TryLock() override;
|
|
|
|
bool HasLockImplementation() override;
|
2023-12-29 15:35:25 +00:00
|
|
|
void SlowLock() override;
|
|
|
|
bool LockMS(AuUInt64 timeout) override;
|
|
|
|
bool LockNS(AuUInt64 timeout) override;
|
|
|
|
bool LockAbsNS(AuUInt64 uTimeout) override;
|
2021-06-27 21:25:29 +00:00
|
|
|
void Unlock() override;
|
|
|
|
|
2023-12-29 15:35:25 +00:00
|
|
|
auline bool TryLockNoSpin();
|
|
|
|
auline bool TryLockHeavy();
|
2021-06-27 21:25:29 +00:00
|
|
|
private:
|
2023-12-29 15:35:25 +00:00
|
|
|
AuUInt32 dwSleeping_ {};
|
2021-06-27 21:25:29 +00:00
|
|
|
};
|
2023-12-29 15:35:25 +00:00
|
|
|
|
|
|
|
using MutexImpl = MutexGenericImpl;
|
2021-06-27 21:25:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|