Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions TUnit.Core/Executors/DedicatedThreadExecutor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -205,10 +205,10 @@ internal sealed class DedicatedThreadTaskScheduler : TaskScheduler
{
private readonly Thread _dedicatedThread;
private readonly ManualResetEventSlim? _workAvailableEvent;
private readonly Lock _queueLock = new();
private readonly List<Task> _taskQueue =
[
];
private readonly Lock _queueLock = new();

public DedicatedThreadTaskScheduler(Thread dedicatedThread, ManualResetEventSlim? workAvailableEvent)
{
Expand Down Expand Up @@ -296,10 +296,10 @@ public bool ProcessPendingTasks()

internal sealed class DedicatedThreadSynchronizationContext : SynchronizationContext
{
private Queue<(SendOrPostCallback callback, object? state)>? _workQueue = null;
private readonly Thread _dedicatedThread;
private readonly DedicatedThreadTaskScheduler _taskScheduler;
private readonly ManualResetEventSlim? _workAvailableEvent;
private readonly Queue<(SendOrPostCallback callback, object? state)> _workQueue = new();
private readonly Lock _queueLock = new();

public DedicatedThreadSynchronizationContext(DedicatedThreadTaskScheduler taskScheduler, ManualResetEventSlim? workAvailableEvent)
Expand All @@ -314,6 +314,7 @@ public override void Post(SendOrPostCallback d, object? state)
// Always queue the work to ensure it runs on the dedicated thread
lock (_queueLock)
{
_workQueue ??= new();
_workQueue.Enqueue((d, state));
}
// Signal that work is available (wake message pump immediately)
Expand Down Expand Up @@ -384,7 +385,7 @@ public bool ProcessPendingWork()

lock (_queueLock)
{
if (_workQueue.Count == 0)
if (_workQueue == null || _workQueue.Count == 0)
{
break;
}
Expand Down
Loading