mirror of
https://github.com/osukey/osukey.git
synced 2025-06-01 10:57:27 +09: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)
|
if (isDisposed)
|
||||||
throw new ObjectDisposedException(nameof(RealmContextFactory));
|
throw new ObjectDisposedException(nameof(RealmContextFactory));
|
||||||
|
|
||||||
|
bool tookSemaphoreLock = false;
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
if (!currentThreadCanCreateContexts.Value)
|
if (!currentThreadCanCreateContexts.Value)
|
||||||
|
{
|
||||||
contextCreationLock.Wait();
|
contextCreationLock.Wait();
|
||||||
|
tookSemaphoreLock = true;
|
||||||
// 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.
|
else
|
||||||
// this can happen if a realm subscription is active and triggers a callback which has user code that calls `CreateContext`.
|
{
|
||||||
currentThreadCanCreateContexts.Value = true;
|
// 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++;
|
contexts_created.Value++;
|
||||||
|
|
||||||
@ -169,8 +176,11 @@ namespace osu.Game.Database
|
|||||||
}
|
}
|
||||||
finally
|
finally
|
||||||
{
|
{
|
||||||
contextCreationLock.Release();
|
if (tookSemaphoreLock)
|
||||||
currentThreadCanCreateContexts.Value = false;
|
{
|
||||||
|
contextCreationLock.Release();
|
||||||
|
currentThreadCanCreateContexts.Value = false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user