Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Core: Wait: Switch to ManualResetEventSlim from AutoResetEvent for thread synchronization. #618

Merged
merged 1 commit into from
Sep 4, 2024
Merged
Show file tree
Hide file tree
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
4 changes: 2 additions & 2 deletions Core/Addon/AddonReader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ namespace Core;
public sealed class AddonReader : IAddonReader
{
private readonly IAddonDataProvider reader;
private readonly AutoResetEvent resetEvent;
private readonly ManualResetEventSlim resetEvent;

private readonly PlayerReader playerReader;
private readonly CreatureDB creatureDb;
Expand All @@ -33,7 +33,7 @@ public sealed class AddonReader : IAddonReader
public double AvgUpdateLatency { private set; get; }

public AddonReader(IAddonDataProvider reader,
PlayerReader playerReader, AutoResetEvent resetEvent,
PlayerReader playerReader, ManualResetEventSlim resetEvent,
CreatureDB creatureDb,
CombatLog combatLog,
DataFrame[] frames,
Expand Down
2 changes: 1 addition & 1 deletion Core/DependencyInjection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ public static IServiceCollection AddCoreNormal(

public static IServiceCollection AddCoreBase(this IServiceCollection s)
{
s.AddSingleton<AutoResetEvent>(x => new(false));
s.AddSingleton<ManualResetEventSlim>(x => new(false));
s.AddSingleton<Wait>();

s.AddSingleton<StartupClientVersion>();
Expand Down
18 changes: 13 additions & 5 deletions Core/GoalsComponent/Wait.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,23 +7,31 @@ namespace Core;

public sealed class Wait
{
private readonly AutoResetEvent globalTime;
private readonly ManualResetEventSlim globalTime;
private readonly CancellationToken token;

public Wait(AutoResetEvent globalTime, CancellationTokenSource cts)
public Wait(ManualResetEventSlim globalTime, CancellationTokenSource cts)
{
this.globalTime = globalTime;
this.token = cts.Token;
}

public void Update()
{
globalTime.WaitOne();
globalTime.Wait();
globalTime.Reset();
}

public bool Update(int timeout)
public bool Update(int timeoutMs)
{
return globalTime.WaitOne(timeout);
bool result = globalTime.Wait(timeoutMs);
if (!result)
{
return result;
}

globalTime.Reset();
return result;
}

public void Fixed(int durationMs)
Expand Down
Loading