aboutsummaryrefslogtreecommitdiff
path: root/Ryujinx.HLE/HOS/Kernel/KReadableEvent.cs
blob: d43fe8249e274cab43bc7a3bffde8b1f464eebf0 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
namespace Ryujinx.HLE.HOS.Kernel
{
    class KReadableEvent : KSynchronizationObject
    {
        private KEvent Parent;

        private bool Signaled;

        public KReadableEvent(Horizon System, KEvent Parent) : base(System)
        {
            this.Parent = Parent;
        }

        public override void Signal()
        {
            System.CriticalSectionLock.Lock();

            if (!Signaled)
            {
                Signaled = true;

                base.Signal();
            }

            System.CriticalSectionLock.Unlock();
        }

        public KernelResult Clear()
        {
            Signaled = false;

            return KernelResult.Success;
        }

        public KernelResult ClearIfSignaled()
        {
            KernelResult Result;

            System.CriticalSectionLock.Lock();

            if (Signaled)
            {
                Signaled = false;

                Result = KernelResult.Success;
            }
            else
            {
                Result = KernelResult.InvalidState;
            }

            System.CriticalSectionLock.Unlock();

            return Result;
        }

        public override bool IsSignaled()
        {
            return Signaled;
        }
    }
}