mirror of
https://github.com/ppy/osu.git
synced 2024-12-15 01:02:55 +08: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 readonly object realmLock = new object();
|
||||
|
||||
private Realm? updateRealm;
|
||||
|
||||
/// <summary>
|
||||
@ -122,8 +120,6 @@ namespace osu.Game.Database
|
||||
if (!ThreadSafety.IsUpdateThread)
|
||||
throw new InvalidOperationException(@$"Use {nameof(getRealmInstance)} when performing realm operations from a non-update thread");
|
||||
|
||||
lock (realmLock)
|
||||
{
|
||||
if (updateRealm == null)
|
||||
{
|
||||
updateRealm = getRealmInstance();
|
||||
@ -140,7 +136,6 @@ namespace osu.Game.Database
|
||||
|
||||
return updateRealm;
|
||||
}
|
||||
}
|
||||
|
||||
internal static bool CurrentThreadSubscriptionsAllowed => current_thread_subscriptions_allowed.Value;
|
||||
|
||||
@ -404,8 +399,6 @@ namespace osu.Game.Database
|
||||
if (!ThreadSafety.IsUpdateThread)
|
||||
throw new InvalidOperationException(@$"{nameof(WriteAsync)} must be called from the update thread.");
|
||||
|
||||
lock (realmLock)
|
||||
{
|
||||
// CountdownEvent will fail if already at zero.
|
||||
if (!pendingAsyncWrites.TryAddCount())
|
||||
pendingAsyncWrites.Reset(1);
|
||||
@ -428,7 +421,6 @@ namespace osu.Game.Database
|
||||
|
||||
return writeTask;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Subscribe to a realm collection and begin watching for asynchronous changes.
|
||||
@ -451,8 +443,6 @@ namespace osu.Game.Database
|
||||
/// <seealso cref="IRealmCollection{T}.SubscribeForNotifications"/>
|
||||
public IDisposable RegisterForNotifications<T>(Func<Realm, IQueryable<T>> query, NotificationCallbackDelegate<T> callback)
|
||||
where T : RealmObjectBase
|
||||
{
|
||||
lock (realmLock)
|
||||
{
|
||||
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));
|
||||
return RegisterCustomSubscription(action);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Subscribe to the property of a realm object to watch for changes.
|
||||
@ -549,8 +538,6 @@ namespace osu.Game.Database
|
||||
updateThreadSyncContext.Post(_ => unsubscribe(), null);
|
||||
|
||||
void unsubscribe()
|
||||
{
|
||||
lock (realmLock)
|
||||
{
|
||||
if (customSubscriptionsResetMap.TryGetValue(action, out var unsubscriptionAction))
|
||||
{
|
||||
@ -560,7 +547,6 @@ namespace osu.Game.Database
|
||||
total_subscriptions.Value--;
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@ -568,8 +554,6 @@ namespace osu.Game.Database
|
||||
{
|
||||
Debug.Assert(ThreadSafety.IsUpdateThread);
|
||||
|
||||
lock (realmLock)
|
||||
{
|
||||
// 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
|
||||
// cyclic invocations of the subscription callback.
|
||||
@ -581,7 +565,6 @@ namespace osu.Game.Database
|
||||
customSubscriptionsResetMap[action] = action(realm);
|
||||
current_thread_subscriptions_allowed.Value = false;
|
||||
}
|
||||
}
|
||||
|
||||
private Realm getRealmInstance()
|
||||
{
|
||||
@ -831,8 +814,6 @@ namespace osu.Game.Database
|
||||
{
|
||||
realmRetrievalLock.Wait();
|
||||
|
||||
lock (realmLock)
|
||||
{
|
||||
if (hasInitialisedOnce)
|
||||
{
|
||||
if (!ThreadSafety.IsUpdateThread)
|
||||
@ -854,7 +835,6 @@ namespace osu.Game.Database
|
||||
}
|
||||
|
||||
Logger.Log(@"Blocking realm operations.", LoggingTarget.Database);
|
||||
}
|
||||
|
||||
const int sleep_length = 200;
|
||||
int timeout = 5000;
|
||||
@ -933,10 +913,7 @@ namespace osu.Game.Database
|
||||
if (!pendingAsyncWrites.Wait(10000))
|
||||
Logger.Log("Realm took too long waiting on pending async writes", level: LogLevel.Error);
|
||||
|
||||
lock (realmLock)
|
||||
{
|
||||
updateRealm?.Dispose();
|
||||
}
|
||||
|
||||
if (!isDisposed)
|
||||
{
|
||||
|
Loading…
Reference in New Issue
Block a user