mirror of
https://github.com/osukey/osukey.git
synced 2025-05-21 21:47:31 +09:00
Fix potential deadlock on nested context creation requests
This commit is contained in:
parent
54798eabc9
commit
c98451a7bf
@ -52,6 +52,8 @@ namespace osu.Game.Database
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
private readonly SemaphoreSlim contextCreationLock = new SemaphoreSlim(1);
|
private readonly SemaphoreSlim contextCreationLock = new SemaphoreSlim(1);
|
||||||
|
|
||||||
|
private bool canCreateContexts;
|
||||||
|
|
||||||
private static readonly GlobalStatistic<int> refreshes = GlobalStatistics.Get<int>(@"Realm", @"Dirty Refreshes");
|
private static readonly GlobalStatistic<int> refreshes = GlobalStatistics.Get<int>(@"Realm", @"Dirty Refreshes");
|
||||||
private static readonly GlobalStatistic<int> contexts_created = GlobalStatistics.Get<int>(@"Realm", @"Contexts (Created)");
|
private static readonly GlobalStatistic<int> contexts_created = GlobalStatistics.Get<int>(@"Realm", @"Contexts (Created)");
|
||||||
|
|
||||||
@ -153,7 +155,13 @@ namespace osu.Game.Database
|
|||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
contextCreationLock.Wait();
|
if (!canCreateContexts)
|
||||||
|
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;
|
||||||
|
|
||||||
contexts_created.Value++;
|
contexts_created.Value++;
|
||||||
|
|
||||||
@ -162,6 +170,7 @@ namespace osu.Game.Database
|
|||||||
finally
|
finally
|
||||||
{
|
{
|
||||||
contextCreationLock.Release();
|
contextCreationLock.Release();
|
||||||
|
canCreateContexts = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user