mirror of
https://github.com/osukey/osukey.git
synced 2025-05-31 02:17:34 +09:00
Fix potential oversight in semaphore release logic
This commit is contained in:
parent
f19cfcc82e
commit
23fded4a3a
@ -153,26 +153,36 @@ namespace osu.Game.Database
|
||||
if (isDisposed)
|
||||
throw new ObjectDisposedException(nameof(RealmContextFactory));
|
||||
|
||||
bool tookSemaphoreLock = false;
|
||||
|
||||
try
|
||||
{
|
||||
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.
|
||||
tookSemaphoreLock = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
// the semaphore is used to handle blocking of all context creation during certain periods.
|
||||
// once the semaphore has been taken by this code section, it is safe to create further contexts on the same thread.
|
||||
// this can happen if a realm subscription is active and triggers a callback which has user code that calls `CreateContext`.
|
||||
currentThreadCanCreateContexts.Value = true;
|
||||
}
|
||||
|
||||
contexts_created.Value++;
|
||||
|
||||
return Realm.GetInstance(getConfiguration());
|
||||
}
|
||||
finally
|
||||
{
|
||||
if (tookSemaphoreLock)
|
||||
{
|
||||
contextCreationLock.Release();
|
||||
currentThreadCanCreateContexts.Value = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private RealmConfiguration getConfiguration()
|
||||
{
|
||||
|
Loading…
x
Reference in New Issue
Block a user