mirror of
https://github.com/ppy/osu
synced 2025-01-05 05:39:49 +00:00
Fix potential oversight in semaphore release logic
This commit is contained in:
parent
f19cfcc82e
commit
23fded4a3a
@ -153,15 +153,22 @@ 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.
|
||||
// this can happen if a realm subscription is active and triggers a callback which has user code that calls `CreateContext`.
|
||||
currentThreadCanCreateContexts.Value = true;
|
||||
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++;
|
||||
|
||||
@ -169,8 +176,11 @@ namespace osu.Game.Database
|
||||
}
|
||||
finally
|
||||
{
|
||||
contextCreationLock.Release();
|
||||
currentThreadCanCreateContexts.Value = false;
|
||||
if (tookSemaphoreLock)
|
||||
{
|
||||
contextCreationLock.Release();
|
||||
currentThreadCanCreateContexts.Value = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user