diff options
| author | gdkchan <gab.dark.100@gmail.com> | 2018-04-18 23:52:23 -0300 |
|---|---|---|
| committer | gdkchan <gab.dark.100@gmail.com> | 2018-04-18 23:52:36 -0300 |
| commit | b9af34f3dd1e7f5e38b038f182c9fd4a791fdfea (patch) | |
| tree | e86e7941f5d2871ed2d9bd702b38997c86fb2af8 /Ryujinx.Core/OsHle/CondVar.cs | |
| parent | e9a96e3522ee7620b525d210915a0e45510ea528 (diff) | |
[HLE/Kernel] Somewhat improved sync primitives
Diffstat (limited to 'Ryujinx.Core/OsHle/CondVar.cs')
| -rw-r--r-- | Ryujinx.Core/OsHle/CondVar.cs | 142 |
1 files changed, 0 insertions, 142 deletions
diff --git a/Ryujinx.Core/OsHle/CondVar.cs b/Ryujinx.Core/OsHle/CondVar.cs deleted file mode 100644 index f1b846d0..00000000 --- a/Ryujinx.Core/OsHle/CondVar.cs +++ /dev/null @@ -1,142 +0,0 @@ -using Ryujinx.Core.OsHle.Handles; -using System.Collections.Generic; -using System.Threading; - -namespace Ryujinx.Core.OsHle -{ - class CondVar - { - private Process Process; - - private long CondVarAddress; - private long Timeout; - - private bool OwnsCondVarValue; - - private List<KThread> WaitingThreads; - - public CondVar(Process Process, long CondVarAddress, long Timeout) - { - this.Process = Process; - this.CondVarAddress = CondVarAddress; - this.Timeout = Timeout; - - WaitingThreads = new List<KThread>(); - } - - public bool WaitForSignal(KThread Thread) - { - int Count = Process.Memory.ReadInt32(CondVarAddress); - - if (Count <= 0) - { - lock (WaitingThreads) - { - WaitingThreads.Add(Thread); - } - - if (Timeout == -1) - { - Process.Scheduler.WaitForSignal(Thread); - } - else - { - bool Result = Process.Scheduler.WaitForSignal(Thread, (int)(Timeout / 1000000)); - - lock (WaitingThreads) - { - WaitingThreads.Remove(Thread); - } - - return Result; - } - } - - AcquireCondVarValue(); - - Count = Process.Memory.ReadInt32(CondVarAddress); - - if (Count > 0) - { - Process.Memory.WriteInt32(CondVarAddress, Count - 1); - } - - ReleaseCondVarValue(); - - return true; - } - - public void SetSignal(KThread Thread, int Count) - { - lock (WaitingThreads) - { - if (Count == -1) - { - Process.Scheduler.Signal(WaitingThreads.ToArray()); - - AcquireCondVarValue(); - - Process.Memory.WriteInt32(CondVarAddress, WaitingThreads.Count); - - ReleaseCondVarValue(); - - WaitingThreads.Clear(); - } - else - { - if (WaitingThreads.Count > 0) - { - int HighestPriority = WaitingThreads[0].Priority; - int HighestPrioIndex = 0; - - for (int Index = 1; Index < WaitingThreads.Count; Index++) - { - if (HighestPriority > WaitingThreads[Index].Priority) - { - HighestPriority = WaitingThreads[Index].Priority; - - HighestPrioIndex = Index; - } - } - - Process.Scheduler.Signal(WaitingThreads[HighestPrioIndex]); - - WaitingThreads.RemoveAt(HighestPrioIndex); - } - - AcquireCondVarValue(); - - Process.Memory.WriteInt32(CondVarAddress, Count); - - ReleaseCondVarValue(); - } - } - - Process.Scheduler.Suspend(Thread.ProcessorId); - Process.Scheduler.Resume(Thread); - } - - private void AcquireCondVarValue() - { - if (!OwnsCondVarValue) - { - while (!Process.Memory.AcquireAddress(CondVarAddress)) - { - Thread.Yield(); - } - - OwnsCondVarValue = true; - } - } - - private void ReleaseCondVarValue() - { - if (OwnsCondVarValue) - { - OwnsCondVarValue = false; - - Process.Memory.ReleaseAddress(CondVarAddress); - } - } - } -}
\ No newline at end of file |
