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

55 lines
1.1 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: CBWaitable.hpp
Date: 2021-6-10
Author: Reece
***/
#pragma once
namespace Aurora::Threading::Waitables
{
struct CBWaitable : IWaitable
2021-06-27 21:25:29 +00:00
{
inline CBWaitable(const AuFunction<bool()> &value) : callback_(value)
2021-06-27 21:25:29 +00:00
{
}
inline bool TryLock() override
2021-06-27 21:25:29 +00:00
{
return this->callback_ ?
this->callback_() :
true;
2021-06-27 21:25:29 +00:00
}
inline bool HasOSHandle(AuMach &mach) override
2021-06-27 21:25:29 +00:00
{
return false;
}
inline bool HasLockImplementation() override
2021-06-27 21:25:29 +00:00
{
return false;
}
inline void Unlock() override
2021-06-27 21:25:29 +00:00
{
}
inline void Lock() override
2021-06-27 21:25:29 +00:00
{
while (!TryLock())
{
ContextYield();
}
2021-06-27 21:25:29 +00:00
}
inline bool LockMS(AuUInt64 timeout) override
2021-06-27 21:25:29 +00:00
{
return TryLock();
2021-06-27 21:25:29 +00:00
}
private:
AuFunction<bool()> callback_;
2021-06-27 21:25:29 +00:00
};
}