mirror of
https://github.com/ppy/osu.git
synced 2024-12-14 16:52:54 +08:00
Move thread safety / locking logic from MultiplayerRoom
This commit is contained in:
parent
575a00dd7d
commit
497d644a19
@ -5,9 +5,7 @@
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Threading;
|
||||
using Newtonsoft.Json;
|
||||
using osu.Framework.Allocation;
|
||||
|
||||
namespace osu.Game.Online.Multiplayer
|
||||
{
|
||||
@ -48,27 +46,6 @@ namespace osu.Game.Online.Multiplayer
|
||||
RoomID = roomId;
|
||||
}
|
||||
|
||||
private object updateLock = new object();
|
||||
|
||||
private ManualResetEventSlim freeForWrite = new ManualResetEventSlim(true);
|
||||
|
||||
/// <summary>
|
||||
/// Request a lock on this room to perform a thread-safe update.
|
||||
/// </summary>
|
||||
public IDisposable LockForUpdate()
|
||||
{
|
||||
// ReSharper disable once InconsistentlySynchronizedField
|
||||
freeForWrite.Wait();
|
||||
|
||||
lock (updateLock)
|
||||
{
|
||||
freeForWrite.Wait();
|
||||
freeForWrite.Reset();
|
||||
|
||||
return new ValueInvokeOnDisposal<MultiplayerRoom>(this, r => freeForWrite.Set());
|
||||
}
|
||||
}
|
||||
|
||||
public override string ToString() => $"RoomID:{RoomID} Host:{Host?.UserID} Users:{Users.Count} State:{State} Settings: [{Settings}]";
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user