aboutsummaryrefslogtreecommitdiff
path: root/src/Ryujinx.Common/PreciseSleep/IPreciseSleepEvent.cs
blob: 26b5ab685ed72fc328043b485ebbde5487be440b (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
using System;

namespace Ryujinx.Common.PreciseSleep
{
    /// <summary>
    /// An event which works similarly to an AutoResetEvent, but is backed by a
    /// more precise timer that allows waits of less than a millisecond.
    /// </summary>
    public interface IPreciseSleepEvent : IDisposable
    {
        /// <summary>
        /// Adjust a timepoint to better fit the host clock.
        /// When no adjustment is made, the input timepoint will be returned.
        /// </summary>
        /// <param name="timePoint">Timepoint to adjust</param>
        /// <param name="timeoutNs">Requested timeout in nanoseconds</param>
        /// <returns>Adjusted timepoint</returns>
        long AdjustTimePoint(long timePoint, long timeoutNs);

        /// <summary>
        /// Sleep until a timepoint, or a signal is received.
        /// Given no signal, may wake considerably before, or slightly after the timeout.
        /// </summary>
        /// <param name="timePoint">Timepoint to sleep until</param>
        /// <returns>True if signalled or waited, false if a wait could not be performed</returns>
        bool SleepUntil(long timePoint);

        /// <summary>
        /// Sleep until a signal is received.
        /// </summary>
        void Sleep();

        /// <summary>
        /// Signal the event, waking any sleeping thread or the next attempted sleep.
        /// </summary>
        void Signal();
    }
}