mirror of
https://github.com/osukey/osukey.git
synced 2025-05-11 08:37:34 +09:00
Remove probably redundant realmLock
As far as I can tell all accesses are safe due to update thread guarantees. The only weird one may be async writes during a `BlockAllOperations`, but the `Compact` loop should handle this quite amicably.
This commit is contained in:
parent
6203885040
commit
e10ac45fd7
@ -98,8 +98,6 @@ namespace osu.Game.Database
|
|||||||
|
|
||||||
private static readonly GlobalStatistic<int> total_writes_async = GlobalStatistics.Get<int>(@"Realm", @"Writes (Async)");
|
private static readonly GlobalStatistic<int> total_writes_async = GlobalStatistics.Get<int>(@"Realm", @"Writes (Async)");
|
||||||
|
|
||||||
private readonly object realmLock = new object();
|
|
||||||
|
|
||||||
private Realm? updateRealm;
|
private Realm? updateRealm;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@ -122,8 +120,6 @@ namespace osu.Game.Database
|
|||||||
if (!ThreadSafety.IsUpdateThread)
|
if (!ThreadSafety.IsUpdateThread)
|
||||||
throw new InvalidOperationException(@$"Use {nameof(getRealmInstance)} when performing realm operations from a non-update thread");
|
throw new InvalidOperationException(@$"Use {nameof(getRealmInstance)} when performing realm operations from a non-update thread");
|
||||||
|
|
||||||
lock (realmLock)
|
|
||||||
{
|
|
||||||
if (updateRealm == null)
|
if (updateRealm == null)
|
||||||
{
|
{
|
||||||
updateRealm = getRealmInstance();
|
updateRealm = getRealmInstance();
|
||||||
@ -140,7 +136,6 @@ namespace osu.Game.Database
|
|||||||
|
|
||||||
return updateRealm;
|
return updateRealm;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
internal static bool CurrentThreadSubscriptionsAllowed => current_thread_subscriptions_allowed.Value;
|
internal static bool CurrentThreadSubscriptionsAllowed => current_thread_subscriptions_allowed.Value;
|
||||||
|
|
||||||
@ -404,8 +399,6 @@ namespace osu.Game.Database
|
|||||||
if (!ThreadSafety.IsUpdateThread)
|
if (!ThreadSafety.IsUpdateThread)
|
||||||
throw new InvalidOperationException(@$"{nameof(WriteAsync)} must be called from the update thread.");
|
throw new InvalidOperationException(@$"{nameof(WriteAsync)} must be called from the update thread.");
|
||||||
|
|
||||||
lock (realmLock)
|
|
||||||
{
|
|
||||||
// CountdownEvent will fail if already at zero.
|
// CountdownEvent will fail if already at zero.
|
||||||
if (!pendingAsyncWrites.TryAddCount())
|
if (!pendingAsyncWrites.TryAddCount())
|
||||||
pendingAsyncWrites.Reset(1);
|
pendingAsyncWrites.Reset(1);
|
||||||
@ -428,7 +421,6 @@ namespace osu.Game.Database
|
|||||||
|
|
||||||
return writeTask;
|
return writeTask;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Subscribe to a realm collection and begin watching for asynchronous changes.
|
/// Subscribe to a realm collection and begin watching for asynchronous changes.
|
||||||
@ -451,8 +443,6 @@ namespace osu.Game.Database
|
|||||||
/// <seealso cref="IRealmCollection{T}.SubscribeForNotifications"/>
|
/// <seealso cref="IRealmCollection{T}.SubscribeForNotifications"/>
|
||||||
public IDisposable RegisterForNotifications<T>(Func<Realm, IQueryable<T>> query, NotificationCallbackDelegate<T> callback)
|
public IDisposable RegisterForNotifications<T>(Func<Realm, IQueryable<T>> query, NotificationCallbackDelegate<T> callback)
|
||||||
where T : RealmObjectBase
|
where T : RealmObjectBase
|
||||||
{
|
|
||||||
lock (realmLock)
|
|
||||||
{
|
{
|
||||||
Func<Realm, IDisposable?> action = realm => query(realm).QueryAsyncWithNotifications(callback);
|
Func<Realm, IDisposable?> action = realm => query(realm).QueryAsyncWithNotifications(callback);
|
||||||
|
|
||||||
@ -460,7 +450,6 @@ namespace osu.Game.Database
|
|||||||
notificationsResetMap.Add(action, () => callback(new EmptyRealmSet<T>(), null, null));
|
notificationsResetMap.Add(action, () => callback(new EmptyRealmSet<T>(), null, null));
|
||||||
return RegisterCustomSubscription(action);
|
return RegisterCustomSubscription(action);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Subscribe to the property of a realm object to watch for changes.
|
/// Subscribe to the property of a realm object to watch for changes.
|
||||||
@ -549,8 +538,6 @@ namespace osu.Game.Database
|
|||||||
updateThreadSyncContext.Post(_ => unsubscribe(), null);
|
updateThreadSyncContext.Post(_ => unsubscribe(), null);
|
||||||
|
|
||||||
void unsubscribe()
|
void unsubscribe()
|
||||||
{
|
|
||||||
lock (realmLock)
|
|
||||||
{
|
{
|
||||||
if (customSubscriptionsResetMap.TryGetValue(action, out var unsubscriptionAction))
|
if (customSubscriptionsResetMap.TryGetValue(action, out var unsubscriptionAction))
|
||||||
{
|
{
|
||||||
@ -560,7 +547,6 @@ namespace osu.Game.Database
|
|||||||
total_subscriptions.Value--;
|
total_subscriptions.Value--;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -568,8 +554,6 @@ namespace osu.Game.Database
|
|||||||
{
|
{
|
||||||
Debug.Assert(ThreadSafety.IsUpdateThread);
|
Debug.Assert(ThreadSafety.IsUpdateThread);
|
||||||
|
|
||||||
lock (realmLock)
|
|
||||||
{
|
|
||||||
// Retrieve realm instance outside of flag update to ensure that the instance is retrieved,
|
// Retrieve realm instance outside of flag update to ensure that the instance is retrieved,
|
||||||
// as attempting to access it inside the subscription if it's not constructed would lead to
|
// as attempting to access it inside the subscription if it's not constructed would lead to
|
||||||
// cyclic invocations of the subscription callback.
|
// cyclic invocations of the subscription callback.
|
||||||
@ -581,7 +565,6 @@ namespace osu.Game.Database
|
|||||||
customSubscriptionsResetMap[action] = action(realm);
|
customSubscriptionsResetMap[action] = action(realm);
|
||||||
current_thread_subscriptions_allowed.Value = false;
|
current_thread_subscriptions_allowed.Value = false;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
private Realm getRealmInstance()
|
private Realm getRealmInstance()
|
||||||
{
|
{
|
||||||
@ -831,8 +814,6 @@ namespace osu.Game.Database
|
|||||||
{
|
{
|
||||||
realmRetrievalLock.Wait();
|
realmRetrievalLock.Wait();
|
||||||
|
|
||||||
lock (realmLock)
|
|
||||||
{
|
|
||||||
if (hasInitialisedOnce)
|
if (hasInitialisedOnce)
|
||||||
{
|
{
|
||||||
if (!ThreadSafety.IsUpdateThread)
|
if (!ThreadSafety.IsUpdateThread)
|
||||||
@ -854,7 +835,6 @@ namespace osu.Game.Database
|
|||||||
}
|
}
|
||||||
|
|
||||||
Logger.Log(@"Blocking realm operations.", LoggingTarget.Database);
|
Logger.Log(@"Blocking realm operations.", LoggingTarget.Database);
|
||||||
}
|
|
||||||
|
|
||||||
const int sleep_length = 200;
|
const int sleep_length = 200;
|
||||||
int timeout = 5000;
|
int timeout = 5000;
|
||||||
@ -933,10 +913,7 @@ namespace osu.Game.Database
|
|||||||
if (!pendingAsyncWrites.Wait(10000))
|
if (!pendingAsyncWrites.Wait(10000))
|
||||||
Logger.Log("Realm took too long waiting on pending async writes", level: LogLevel.Error);
|
Logger.Log("Realm took too long waiting on pending async writes", level: LogLevel.Error);
|
||||||
|
|
||||||
lock (realmLock)
|
|
||||||
{
|
|
||||||
updateRealm?.Dispose();
|
updateRealm?.Dispose();
|
||||||
}
|
|
||||||
|
|
||||||
if (!isDisposed)
|
if (!isDisposed)
|
||||||
{
|
{
|
||||||
|
Loading…
x
Reference in New Issue
Block a user