mirror of
https://github.com/ppy/osu.git
synced 2024-12-14 19:22:54 +08:00
Merge pull request #3397 from peppy/fix-collection-modified
Fix thread-safety of queued events list in ArchiveModelManager
This commit is contained in:
commit
dbcbd82554
@ -59,7 +59,7 @@ namespace osu.Game.Database
|
||||
// ReSharper disable once NotAccessedField.Local (we should keep a reference to this so it is not finalised)
|
||||
private ArchiveImportIPCChannel ipc;
|
||||
|
||||
private readonly List<Action> cachedEvents = new List<Action>();
|
||||
private readonly List<Action> queuedEvents = new List<Action>();
|
||||
|
||||
/// <summary>
|
||||
/// Allows delaying of outwards events until an operation is confirmed (at a database level).
|
||||
@ -77,20 +77,26 @@ namespace osu.Game.Database
|
||||
/// <param name="perform">Whether the flushed events should be performed.</param>
|
||||
private void flushEvents(bool perform)
|
||||
{
|
||||
Action[] events;
|
||||
lock (queuedEvents)
|
||||
{
|
||||
events = queuedEvents.ToArray();
|
||||
queuedEvents.Clear();
|
||||
}
|
||||
|
||||
if (perform)
|
||||
{
|
||||
foreach (var a in cachedEvents)
|
||||
foreach (var a in events)
|
||||
a.Invoke();
|
||||
}
|
||||
|
||||
cachedEvents.Clear();
|
||||
delayingEvents = false;
|
||||
}
|
||||
|
||||
private void handleEvent(Action a)
|
||||
{
|
||||
if (delayingEvents)
|
||||
cachedEvents.Add(a);
|
||||
lock (queuedEvents) queuedEvents.Add(a);
|
||||
else
|
||||
a.Invoke();
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user