mirror of
https://github.com/ppy/osu.git
synced 2024-12-15 01:02:55 +08:00
Add unregistration on blocking
This is the first part of the requirement of sending a `ChangeSet` event to ensure correct state during blocking time
This commit is contained in:
parent
bd0eda7e90
commit
f39ff1eacb
@ -247,6 +247,8 @@ namespace osu.Game.Database
|
||||
|
||||
registerSubscription(action);
|
||||
|
||||
// This token is returned to the consumer only.
|
||||
// It will cause the registration to be permanently removed.
|
||||
return new InvokeOnDisposal(() =>
|
||||
{
|
||||
lock (contextLock)
|
||||
@ -269,12 +271,27 @@ namespace osu.Game.Database
|
||||
|
||||
lock (contextLock)
|
||||
{
|
||||
Debug.Assert(!customSubscriptionActions.TryGetValue(action, out var found) || found == null);
|
||||
|
||||
current_thread_subscriptions_allowed.Value = true;
|
||||
subscriptionActions[action] = action(realm);
|
||||
current_thread_subscriptions_allowed.Value = false;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Unregister all subscriptions when the realm context is to be recycled.
|
||||
/// Subscriptions will still remain and will be re-subscribed when the realm context returns.
|
||||
/// </summary>
|
||||
private void unregisterAllSubscriptions()
|
||||
{
|
||||
foreach (var action in subscriptionActions)
|
||||
{
|
||||
action.Value?.Dispose();
|
||||
subscriptionActions[action.Key] = null;
|
||||
}
|
||||
}
|
||||
|
||||
private Realm createContext()
|
||||
{
|
||||
if (isDisposed)
|
||||
@ -519,6 +536,7 @@ namespace osu.Game.Database
|
||||
throw new InvalidOperationException(@$"{nameof(BlockAllOperations)} must be called from the update thread.");
|
||||
|
||||
syncContext = SynchronizationContext.Current;
|
||||
unregisterAllSubscriptions();
|
||||
|
||||
Logger.Log(@"Blocking realm operations.", LoggingTarget.Database);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user