Skip to content

Commit

Permalink
Make _eventReadyTokenSource readonly.
Browse files Browse the repository at this point in the history
  • Loading branch information
BDisp committed Jun 4, 2024
1 parent d173d59 commit e03b20e
Showing 1 changed file with 10 additions and 16 deletions.
26 changes: 10 additions & 16 deletions Terminal.Gui/ConsoleDrivers/NetDriver.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1690,7 +1690,7 @@ internal class NetMainLoop : IMainLoopDriver
private readonly CancellationTokenSource _inputHandlerTokenSource = new ();
private readonly Queue<InputResult?> _resultQueue = new ();
private readonly ManualResetEventSlim _waitForProbe = new (false);
private CancellationTokenSource _eventReadyTokenSource = new ();
private readonly CancellationTokenSource _eventReadyTokenSource = new ();
private MainLoop _mainLoop;

/// <summary>Initializes the class with the console driver.</summary>
Expand Down Expand Up @@ -1742,14 +1742,13 @@ bool IMainLoopDriver.EventsPending ()
_eventReady.Reset ();
}

_eventReadyTokenSource.Token.ThrowIfCancellationRequested ();

if (!_eventReadyTokenSource.IsCancellationRequested)
{
return _resultQueue.Count > 0 || _mainLoop.CheckTimersAndIdleHandlers (out _);
}

_eventReadyTokenSource.Dispose ();
_eventReadyTokenSource = new CancellationTokenSource ();

return true;
}

Expand Down Expand Up @@ -1806,26 +1805,21 @@ private void NetInputHandler ()
return;
}

_inputHandlerTokenSource.Token.ThrowIfCancellationRequested ();

if (_resultQueue.Count == 0)
{
_resultQueue.Enqueue (_netEvents.DequeueInput ());
}

try
while (_resultQueue.Count > 0 && _resultQueue.Peek () is null)
{
while (_resultQueue.Peek () is null)
{
_resultQueue.Dequeue ();
}

if (_resultQueue.Count > 0)
{
_eventReady.Set ();
}
_resultQueue.Dequeue ();
}
catch (InvalidOperationException)

if (_resultQueue.Count > 0)
{
// Ignore
_eventReady.Set ();
}
}
}
Expand Down

0 comments on commit e03b20e

Please sign in to comment.