diff --git a/osu.Game/Database/RealmContextFactory.cs b/osu.Game/Database/RealmContextFactory.cs index 08d7580db7..9e66248d78 100644 --- a/osu.Game/Database/RealmContextFactory.cs +++ b/osu.Game/Database/RealmContextFactory.cs @@ -52,7 +52,7 @@ namespace osu.Game.Database /// private readonly SemaphoreSlim contextCreationLock = new SemaphoreSlim(1); - private bool canCreateContexts; + private ThreadLocal currentThreadCanCreateContexts = new ThreadLocal(); private static readonly GlobalStatistic refreshes = GlobalStatistics.Get(@"Realm", @"Dirty Refreshes"); private static readonly GlobalStatistic contexts_created = GlobalStatistics.Get(@"Realm", @"Contexts (Created)"); @@ -155,13 +155,13 @@ namespace osu.Game.Database try { - if (!canCreateContexts) + if (!currentThreadCanCreateContexts.Value) contextCreationLock.Wait(); // the semaphore is used to stop all context creation. // once the semaphore has been taken by this code section, it is safe to create further contexts. // this can happen if a realm subscription is active and triggers a callback which has user code that calls `CreateContext`. - canCreateContexts = true; + currentThreadCanCreateContexts.Value = true; contexts_created.Value++; @@ -170,7 +170,7 @@ namespace osu.Game.Database finally { contextCreationLock.Release(); - canCreateContexts = false; + currentThreadCanCreateContexts.Value = false; } }