aboutsummaryrefslogtreecommitdiff
path: root/ARMeilleure/Translation/TranslatorQueue.cs
diff options
context:
space:
mode:
authorTSR Berry <20988865+TSRBerry@users.noreply.github.com>2023-04-08 01:22:00 +0200
committerMary <thog@protonmail.com>2023-04-27 23:51:14 +0200
commitcee712105850ac3385cd0091a923438167433f9f (patch)
tree4a5274b21d8b7f938c0d0ce18736d3f2993b11b1 /ARMeilleure/Translation/TranslatorQueue.cs
parentcd124bda587ef09668a971fa1cac1c3f0cfc9f21 (diff)
Move solution and projects to src
Diffstat (limited to 'ARMeilleure/Translation/TranslatorQueue.cs')
-rw-r--r--ARMeilleure/Translation/TranslatorQueue.cs121
1 files changed, 0 insertions, 121 deletions
diff --git a/ARMeilleure/Translation/TranslatorQueue.cs b/ARMeilleure/Translation/TranslatorQueue.cs
deleted file mode 100644
index fc0aa64f..00000000
--- a/ARMeilleure/Translation/TranslatorQueue.cs
+++ /dev/null
@@ -1,121 +0,0 @@
-using ARMeilleure.Diagnostics;
-using ARMeilleure.State;
-using System;
-using System.Collections.Generic;
-using System.Threading;
-
-namespace ARMeilleure.Translation
-{
- /// <summary>
- /// Represents a queue of <see cref="RejitRequest"/>.
- /// </summary>
- /// <remarks>
- /// This does not necessarily behave like a queue, i.e: a FIFO collection.
- /// </remarks>
- sealed class TranslatorQueue : IDisposable
- {
- private bool _disposed;
- private readonly Stack<RejitRequest> _requests;
- private readonly HashSet<ulong> _requestAddresses;
-
- /// <summary>
- /// Gets the object used to synchronize access to the <see cref="TranslatorQueue"/>.
- /// </summary>
- public object Sync { get; }
-
- /// <summary>
- /// Gets the number of requests in the <see cref="TranslatorQueue"/>.
- /// </summary>
- public int Count => _requests.Count;
-
- /// <summary>
- /// Initializes a new instance of the <see cref="TranslatorQueue"/> class.
- /// </summary>
- public TranslatorQueue()
- {
- Sync = new object();
-
- _requests = new Stack<RejitRequest>();
- _requestAddresses = new HashSet<ulong>();
- }
-
- /// <summary>
- /// Enqueues a request with the specified <paramref name="address"/> and <paramref name="mode"/>.
- /// </summary>
- /// <param name="address">Address of request</param>
- /// <param name="mode"><see cref="ExecutionMode"/> of request</param>
- public void Enqueue(ulong address, ExecutionMode mode)
- {
- lock (Sync)
- {
- if (_requestAddresses.Add(address))
- {
- _requests.Push(new RejitRequest(address, mode));
-
- TranslatorEventSource.Log.RejitQueueAdd(1);
-
- Monitor.Pulse(Sync);
- }
- }
- }
-
- /// <summary>
- /// Tries to dequeue a <see cref="RejitRequest"/>. This will block the thread until a <see cref="RejitRequest"/>
- /// is enqueued or the <see cref="TranslatorQueue"/> is disposed.
- /// </summary>
- /// <param name="result"><see cref="RejitRequest"/> dequeued</param>
- /// <returns><see langword="true"/> on success; otherwise <see langword="false"/></returns>
- public bool TryDequeue(out RejitRequest result)
- {
- while (!_disposed)
- {
- lock (Sync)
- {
- if (_requests.TryPop(out result))
- {
- _requestAddresses.Remove(result.Address);
-
- TranslatorEventSource.Log.RejitQueueAdd(-1);
-
- return true;
- }
-
- Monitor.Wait(Sync);
- }
- }
-
- result = default;
-
- return false;
- }
-
- /// <summary>
- /// Clears the <see cref="TranslatorQueue"/>.
- /// </summary>
- public void Clear()
- {
- lock (Sync)
- {
- TranslatorEventSource.Log.RejitQueueAdd(-_requests.Count);
-
- _requests.Clear();
- _requestAddresses.Clear();
-
- Monitor.PulseAll(Sync);
- }
- }
-
- /// <summary>
- /// Releases all resources used by the <see cref="TranslatorQueue"/> instance.
- /// </summary>
- public void Dispose()
- {
- if (!_disposed)
- {
- _disposed = true;
-
- Clear();
- }
- }
- }
-}