mirror of
https://github.com/ppy/osu.git
synced 2024-12-14 10:52:53 +08:00
Merge pull request #25931 from peppy/fix-thread-safety
Fix thread safety of `OnlineMetadataClient.UserStates`
This commit is contained in:
commit
83e885192b
@ -97,8 +97,11 @@ namespace osu.Game.Online.Metadata
|
||||
{
|
||||
if (!connected.NewValue)
|
||||
{
|
||||
isWatchingUserPresence.Value = false;
|
||||
userStates.Clear();
|
||||
Schedule(() =>
|
||||
{
|
||||
isWatchingUserPresence.Value = false;
|
||||
userStates.Clear();
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
@ -187,13 +190,13 @@ namespace osu.Game.Online.Metadata
|
||||
|
||||
public override Task UserPresenceUpdated(int userId, UserPresence? presence)
|
||||
{
|
||||
lock (userStates)
|
||||
Schedule(() =>
|
||||
{
|
||||
if (presence != null)
|
||||
userStates[userId] = presence.Value;
|
||||
else
|
||||
userStates.Remove(userId);
|
||||
}
|
||||
});
|
||||
|
||||
return Task.CompletedTask;
|
||||
}
|
||||
@ -205,7 +208,7 @@ namespace osu.Game.Online.Metadata
|
||||
|
||||
Debug.Assert(connection != null);
|
||||
await connection.InvokeAsync(nameof(IMetadataServer.BeginWatchingUserPresence)).ConfigureAwait(false);
|
||||
isWatchingUserPresence.Value = true;
|
||||
Schedule(() => isWatchingUserPresence.Value = true);
|
||||
}
|
||||
|
||||
public override async Task EndWatchingUserPresence()
|
||||
@ -215,14 +218,14 @@ namespace osu.Game.Online.Metadata
|
||||
if (connector?.IsConnected.Value != true)
|
||||
throw new OperationCanceledException();
|
||||
|
||||
// must happen synchronously before any remote calls to avoid misordering.
|
||||
userStates.Clear();
|
||||
// must be scheduled before any remote calls to avoid mis-ordering.
|
||||
Schedule(() => userStates.Clear());
|
||||
Debug.Assert(connection != null);
|
||||
await connection.InvokeAsync(nameof(IMetadataServer.EndWatchingUserPresence)).ConfigureAwait(false);
|
||||
}
|
||||
finally
|
||||
{
|
||||
isWatchingUserPresence.Value = false;
|
||||
Schedule(() => isWatchingUserPresence.Value = false);
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user