Skip to content

Commit

Permalink
Limit concurrency using a semaphore instead of dodgy task factory
Browse files Browse the repository at this point in the history
  • Loading branch information
peppy committed Jun 11, 2024
1 parent af78727 commit 4f7b3e2
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions GlobalRankLookupCache/Controllers/BeatmapRankCache.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
using System;
using System.Collections.Generic;
using System.Threading;
using System.Threading.Tasks;
using osu.Framework.Threading;

namespace GlobalRankLookupCache.Controllers
{
Expand Down Expand Up @@ -84,17 +84,17 @@ private void queuePopulation()
if (!populationInProgress)
{
populationInProgress = true;
task_factory.StartNew(repopulateScores);
Task.Run(repopulateScores);
}
}
}

private static readonly ThreadedTaskScheduler task_scheduler = new ThreadedTaskScheduler(10, "retrieval");

private static readonly TaskFactory task_factory = new TaskFactory(task_scheduler);
private static readonly SemaphoreSlim population_tasks_semaphore = new SemaphoreSlim(10);

private async Task repopulateScores()
{
await population_tasks_semaphore.WaitAsync();

var scores = new List<int>();

try
Expand Down Expand Up @@ -138,6 +138,7 @@ private async Task repopulateScores()
// will retry next lookup
}

population_tasks_semaphore.Release();
populationInProgress = false;
}
}
Expand Down

0 comments on commit 4f7b3e2

Please sign in to comment.