mirror of
https://github.com/osukey/osukey.git
synced 2025-05-29 09:27:18 +09: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);
|
registerSubscription(action);
|
||||||
|
|
||||||
|
// This token is returned to the consumer only.
|
||||||
|
// It will cause the registration to be permanently removed.
|
||||||
return new InvokeOnDisposal(() =>
|
return new InvokeOnDisposal(() =>
|
||||||
{
|
{
|
||||||
lock (contextLock)
|
lock (contextLock)
|
||||||
@ -269,12 +271,27 @@ namespace osu.Game.Database
|
|||||||
|
|
||||||
lock (contextLock)
|
lock (contextLock)
|
||||||
{
|
{
|
||||||
|
Debug.Assert(!customSubscriptionActions.TryGetValue(action, out var found) || found == null);
|
||||||
|
|
||||||
current_thread_subscriptions_allowed.Value = true;
|
current_thread_subscriptions_allowed.Value = true;
|
||||||
subscriptionActions[action] = action(realm);
|
subscriptionActions[action] = action(realm);
|
||||||
current_thread_subscriptions_allowed.Value = false;
|
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()
|
private Realm createContext()
|
||||||
{
|
{
|
||||||
if (isDisposed)
|
if (isDisposed)
|
||||||
@ -519,6 +536,7 @@ namespace osu.Game.Database
|
|||||||
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;
|
syncContext = SynchronizationContext.Current;
|
||||||
|
unregisterAllSubscriptions();
|
||||||
|
|
||||||
Logger.Log(@"Blocking realm operations.", LoggingTarget.Database);
|
Logger.Log(@"Blocking realm operations.", LoggingTarget.Database);
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user