AuroraRuntime/Include/Aurora/Threading/Waitables/CBWaitable.hpp

55 lines
1.1 KiB
C++

/***
Copyright (C) 2021 J Reece Wilson (a/k/a "Reece"). All rights reserved.
File: CBWaitable.hpp
Date: 2021-6-10
Author: Reece
***/
#pragma once
namespace Aurora::Threading::Waitables
{
struct CBWaitable : IWaitable
{
inline CBWaitable(const AuFunction<bool()> &value) : callback_(value)
{
}
inline bool TryLock() override
{
return this->callback_ ?
this->callback_() :
true;
}
inline bool HasOSHandle(AuMach &mach) override
{
return false;
}
inline bool HasLockImplementation() override
{
return false;
}
inline void Unlock() override
{
}
inline void Lock() override
{
while (!TryLock())
{
ContextYield();
}
}
inline bool LockMS(AuUInt64 timeout) override
{
return TryLock();
}
private:
AuFunction<bool()> callback_;
};
}