Skip to content

Commit

Permalink
Ensure to always reset execution mode
Browse files Browse the repository at this point in the history
  • Loading branch information
smoogipoo committed Jul 17, 2024
1 parent 344700f commit eefe674
Showing 1 changed file with 19 additions and 13 deletions.
32 changes: 19 additions & 13 deletions osu.Framework/Testing/HeadlessThreadRunner.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// Copyright (c) ppy Pty Ltd <[email protected]>. Licensed under the MIT Licence.
// See the LICENCE file in the repository root for full licence text.

using System;

Check failure on line 4 in osu.Framework/Testing/HeadlessThreadRunner.cs

View workflow job for this annotation

GitHub Actions / Code Quality

Using directive is unnecessary. (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/style-rules/ide0005)

Check failure on line 4 in osu.Framework/Testing/HeadlessThreadRunner.cs

View workflow job for this annotation

GitHub Actions / Code Quality

Using directive is unnecessary. (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/style-rules/ide0005)
using osu.Framework.Development;
using osu.Framework.Platform;
using osu.Framework.Threading;
Expand All @@ -27,25 +28,30 @@ public override void RunMainLoop()
// Run a simulated multi-threaded mode.
// This is because the CI test runners are usually CPU-limited and may be preferring one thread (audio) over another (update).

ThreadSafety.ExecutionMode = ExecutionMode.SingleThread;

for (int i = 0; i < Threads.Count; i++)
try
{
int from;
int to;
ThreadSafety.ExecutionMode = ExecutionMode.SingleThread;

do
for (int i = 0; i < Threads.Count; i++)
{
from = RNG.Next(Threads.Count);
to = RNG.Next(Threads.Count);
} while (from == to);
int from;
int to;

(Threads[from], Threads[to]) = (Threads[to], Threads[from]);
}
do
{
from = RNG.Next(Threads.Count);
to = RNG.Next(Threads.Count);
} while (from == to);

base.RunMainLoop();
(Threads[from], Threads[to]) = (Threads[to], Threads[from]);
}

ThreadSafety.ExecutionMode = ExecutionMode.MultiThreaded;
base.RunMainLoop();
}
finally
{
ThreadSafety.ExecutionMode = ExecutionMode.MultiThreaded;
}
}
}
}

0 comments on commit eefe674

Please sign in to comment.