aboutsummaryrefslogtreecommitdiff
path: root/src/Ryujinx.Horizon/Sdk/Audio/AudioEvent.cs
blob: efa8d5bc15f7740da188e050d4dd20c874dd8d6c (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
using Ryujinx.Audio.Integration;
using Ryujinx.Horizon.Common;
using Ryujinx.Horizon.Sdk.OsTypes;
using System;

namespace Ryujinx.Horizon.Sdk.Audio
{
    class AudioEvent : IWritableEvent, IDisposable
    {
        private SystemEventType _systemEvent;
        private readonly IExternalEvent _externalEvent;

        public AudioEvent()
        {
            Os.CreateSystemEvent(out _systemEvent, EventClearMode.ManualClear, interProcess: true);

            // We need to do this because the event will be signalled from a different thread.
            _externalEvent = HorizonStatic.Syscall.GetExternalEvent(Os.GetWritableHandleOfSystemEvent(ref _systemEvent));
        }

        public void Signal()
        {
            _externalEvent.Signal();
        }

        public void Clear()
        {
            _externalEvent.Clear();
        }

        public int GetReadableHandle()
        {
            return Os.GetReadableHandleOfSystemEvent(ref _systemEvent);
        }

        protected virtual void Dispose(bool disposing)
        {
            if (disposing)
            {
                Os.DestroySystemEvent(ref _systemEvent);
            }
        }

        public void Dispose()
        {
            Dispose(disposing: true);
            GC.SuppressFinalize(this);
        }
    }
}