mirror of
https://github.com/ppy/osu.git
synced 2025-01-13 19:43:22 +08:00
Use a more reliable method of reviving the update thread realm after blocking
This commit is contained in:
parent
3b11235d3c
commit
ad3a01dc06
@ -69,9 +69,9 @@ namespace osu.Game.Database
|
|||||||
|
|
||||||
private Realm? context;
|
private Realm? context;
|
||||||
|
|
||||||
public Realm Context
|
public Realm Context => ensureUpdateContext();
|
||||||
{
|
|
||||||
get
|
private Realm ensureUpdateContext()
|
||||||
{
|
{
|
||||||
if (!ThreadSafety.IsUpdateThread)
|
if (!ThreadSafety.IsUpdateThread)
|
||||||
throw new InvalidOperationException(@$"Use {nameof(createContext)} when performing realm operations from a non-update thread");
|
throw new InvalidOperationException(@$"Use {nameof(createContext)} when performing realm operations from a non-update thread");
|
||||||
@ -94,7 +94,6 @@ namespace osu.Game.Database
|
|||||||
return context;
|
return context;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
internal static bool CurrentThreadSubscriptionsAllowed => current_thread_subscriptions_allowed.Value;
|
internal static bool CurrentThreadSubscriptionsAllowed => current_thread_subscriptions_allowed.Value;
|
||||||
|
|
||||||
@ -506,6 +505,8 @@ namespace osu.Game.Database
|
|||||||
if (isDisposed)
|
if (isDisposed)
|
||||||
throw new ObjectDisposedException(nameof(RealmContextFactory));
|
throw new ObjectDisposedException(nameof(RealmContextFactory));
|
||||||
|
|
||||||
|
SynchronizationContext syncContext;
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
contextCreationLock.Wait();
|
contextCreationLock.Wait();
|
||||||
@ -515,6 +516,8 @@ namespace osu.Game.Database
|
|||||||
if (!ThreadSafety.IsUpdateThread && context != null)
|
if (!ThreadSafety.IsUpdateThread && context != null)
|
||||||
throw new InvalidOperationException(@$"{nameof(BlockAllOperations)} must be called from the update thread.");
|
throw new InvalidOperationException(@$"{nameof(BlockAllOperations)} must be called from the update thread.");
|
||||||
|
|
||||||
|
syncContext = SynchronizationContext.Current;
|
||||||
|
|
||||||
Logger.Log(@"Blocking realm operations.", LoggingTarget.Database);
|
Logger.Log(@"Blocking realm operations.", LoggingTarget.Database);
|
||||||
|
|
||||||
context?.Dispose();
|
context?.Dispose();
|
||||||
@ -553,6 +556,9 @@ namespace osu.Game.Database
|
|||||||
{
|
{
|
||||||
factory.contextCreationLock.Release();
|
factory.contextCreationLock.Release();
|
||||||
Logger.Log(@"Restoring realm operations.", LoggingTarget.Database);
|
Logger.Log(@"Restoring realm operations.", LoggingTarget.Database);
|
||||||
|
|
||||||
|
// Post back to the update thread to revive any subscriptions.
|
||||||
|
syncContext?.Post(_ => ensureUpdateContext(), null);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -33,10 +33,6 @@ namespace osu.Game.Overlays.Settings.Sections.DebugSettings
|
|||||||
using (realmFactory.BlockAllOperations())
|
using (realmFactory.BlockAllOperations())
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
// retrieve context to revive realm subscriptions.
|
|
||||||
// TODO: should we do this from OsuGame or RealmContextFactory or something? Answer: yes.
|
|
||||||
var _ = realmFactory.Context;
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
Loading…
Reference in New Issue
Block a user