mirror of
https://github.com/ppy/osu.git
synced 2025-02-27 14:43:07 +08:00
Add safety against double disposal
This commit is contained in:
parent
842f033522
commit
90f0bc87f5
@ -126,22 +126,28 @@ namespace osu.Game.Database
|
|||||||
|
|
||||||
protected override void Dispose(bool isDisposing)
|
protected override void Dispose(bool isDisposing)
|
||||||
{
|
{
|
||||||
base.Dispose(isDisposing);
|
if (!IsDisposed)
|
||||||
|
{
|
||||||
// intentionally block all operations indefinitely. this ensures that nothing can start consuming a new context after disposal.
|
// intentionally block all operations indefinitely. this ensures that nothing can start consuming a new context after disposal.
|
||||||
BlockAllOperations();
|
BlockAllOperations();
|
||||||
blockingLock?.Dispose();
|
blockingLock?.Dispose();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
base.Dispose(isDisposing);
|
||||||
|
}
|
||||||
|
|
||||||
public IDisposable BlockAllOperations()
|
public IDisposable BlockAllOperations()
|
||||||
{
|
{
|
||||||
|
if (IsDisposed)
|
||||||
|
throw new InvalidOperationException(@"Attempted to block operations after already disposed.");
|
||||||
|
|
||||||
blockingLock.Wait();
|
blockingLock.Wait();
|
||||||
flushContexts();
|
flushContexts();
|
||||||
|
|
||||||
return new InvokeOnDisposal<RealmContextFactory>(this, endBlockingSection);
|
return new InvokeOnDisposal<RealmContextFactory>(this, endBlockingSection);
|
||||||
}
|
|
||||||
|
|
||||||
private static void endBlockingSection(RealmContextFactory factory) => factory.blockingLock.Release();
|
static void endBlockingSection(RealmContextFactory factory) => factory.blockingLock.Release();
|
||||||
|
}
|
||||||
|
|
||||||
private void flushContexts()
|
private void flushContexts()
|
||||||
{
|
{
|
||||||
|
Loading…
Reference in New Issue
Block a user