2018-12-17 21:33:36 -08:00
|
|
|
using Ryujinx.HLE.HOS.Kernel.Common;
|
2023-01-04 14:15:45 -08:00
|
|
|
using Ryujinx.Horizon.Common;
|
2018-12-17 21:33:36 -08:00
|
|
|
|
|
|
|
namespace Ryujinx.HLE.HOS.Kernel.Threading
|
2018-09-23 11:11:46 -07:00
|
|
|
{
|
|
|
|
class KReadableEvent : KSynchronizationObject
|
|
|
|
{
|
2020-05-03 20:41:29 -07:00
|
|
|
private readonly KEvent _parent;
|
2018-09-23 11:11:46 -07:00
|
|
|
|
2018-12-06 03:16:24 -08:00
|
|
|
private bool _signaled;
|
2018-09-23 11:11:46 -07:00
|
|
|
|
2020-05-03 20:41:29 -07:00
|
|
|
public KReadableEvent(KernelContext context, KEvent parent) : base(context)
|
2018-09-23 11:11:46 -07:00
|
|
|
{
|
2018-12-06 03:16:24 -08:00
|
|
|
_parent = parent;
|
2018-09-23 11:11:46 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
public override void Signal()
|
|
|
|
{
|
2020-05-03 20:41:29 -07:00
|
|
|
KernelContext.CriticalSection.Enter();
|
2018-09-23 11:11:46 -07:00
|
|
|
|
2018-12-06 03:16:24 -08:00
|
|
|
if (!_signaled)
|
2018-09-23 11:11:46 -07:00
|
|
|
{
|
2018-12-06 03:16:24 -08:00
|
|
|
_signaled = true;
|
2018-09-23 11:11:46 -07:00
|
|
|
|
|
|
|
base.Signal();
|
|
|
|
}
|
|
|
|
|
2020-05-03 20:41:29 -07:00
|
|
|
KernelContext.CriticalSection.Leave();
|
2018-09-23 11:11:46 -07:00
|
|
|
}
|
|
|
|
|
2023-01-04 14:15:45 -08:00
|
|
|
public Result Clear()
|
2018-09-23 11:11:46 -07:00
|
|
|
{
|
2018-12-06 03:16:24 -08:00
|
|
|
_signaled = false;
|
2018-09-23 11:11:46 -07:00
|
|
|
|
2023-01-04 14:15:45 -08:00
|
|
|
return Result.Success;
|
2018-09-23 11:11:46 -07:00
|
|
|
}
|
|
|
|
|
2023-01-04 14:15:45 -08:00
|
|
|
public Result ClearIfSignaled()
|
2018-09-23 11:11:46 -07:00
|
|
|
{
|
2023-01-04 14:15:45 -08:00
|
|
|
Result result;
|
2018-09-23 11:11:46 -07:00
|
|
|
|
2020-05-03 20:41:29 -07:00
|
|
|
KernelContext.CriticalSection.Enter();
|
2018-09-23 11:11:46 -07:00
|
|
|
|
2018-12-06 03:16:24 -08:00
|
|
|
if (_signaled)
|
2018-09-23 11:11:46 -07:00
|
|
|
{
|
2018-12-06 03:16:24 -08:00
|
|
|
_signaled = false;
|
2018-09-23 11:11:46 -07:00
|
|
|
|
2023-01-04 14:15:45 -08:00
|
|
|
result = Result.Success;
|
2018-09-23 11:11:46 -07:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2018-12-06 03:16:24 -08:00
|
|
|
result = KernelResult.InvalidState;
|
2018-09-23 11:11:46 -07:00
|
|
|
}
|
|
|
|
|
2020-05-03 20:41:29 -07:00
|
|
|
KernelContext.CriticalSection.Leave();
|
2018-09-23 11:11:46 -07:00
|
|
|
|
2018-12-06 03:16:24 -08:00
|
|
|
return result;
|
2018-09-23 11:11:46 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
public override bool IsSignaled()
|
|
|
|
{
|
2018-12-06 03:16:24 -08:00
|
|
|
return _signaled;
|
2018-09-23 11:11:46 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|