From 9ff742013bcf985f5a8a066108ae7dc4816709bb Mon Sep 17 00:00:00 2001
From: rlauu <46294892+rlauu@users.noreply.github.com>
Date: Mon, 23 Sep 2024 19:45:16 +0200
Subject: [PATCH] clean up semaphore
---
.../ScheduledTasks/DetectCreditsTask.cs | 2 +-
.../ScheduledTasks/DetectIntrosCreditsTask.cs | 2 +-
.../ScheduledTasks/DetectIntrosTask.cs | 2 +-
.../ScheduledTasks/ScheduledTaskSemaphore.cs | 17 +++--------------
.../Services/Entrypoint.cs | 2 +-
5 files changed, 7 insertions(+), 18 deletions(-)
diff --git a/ConfusedPolarBear.Plugin.IntroSkipper/ScheduledTasks/DetectCreditsTask.cs b/ConfusedPolarBear.Plugin.IntroSkipper/ScheduledTasks/DetectCreditsTask.cs
index 06109e6..7706da4 100644
--- a/ConfusedPolarBear.Plugin.IntroSkipper/ScheduledTasks/DetectCreditsTask.cs
+++ b/ConfusedPolarBear.Plugin.IntroSkipper/ScheduledTasks/DetectCreditsTask.cs
@@ -78,7 +78,7 @@ public class DetectCreditsTask : IScheduledTask
Entrypoint.CancelAutomaticTask(cancellationToken);
}
- using (ScheduledTaskSemaphore.Acquire(-1, cancellationToken))
+ using (ScheduledTaskSemaphore.Acquire(cancellationToken))
{
_logger.LogInformation("Scheduled Task is starting");
diff --git a/ConfusedPolarBear.Plugin.IntroSkipper/ScheduledTasks/DetectIntrosCreditsTask.cs b/ConfusedPolarBear.Plugin.IntroSkipper/ScheduledTasks/DetectIntrosCreditsTask.cs
index af730b9..72e8fee 100644
--- a/ConfusedPolarBear.Plugin.IntroSkipper/ScheduledTasks/DetectIntrosCreditsTask.cs
+++ b/ConfusedPolarBear.Plugin.IntroSkipper/ScheduledTasks/DetectIntrosCreditsTask.cs
@@ -77,7 +77,7 @@ public class DetectIntrosCreditsTask : IScheduledTask
Entrypoint.CancelAutomaticTask(cancellationToken);
}
- using (ScheduledTaskSemaphore.Acquire(-1, cancellationToken))
+ using (ScheduledTaskSemaphore.Acquire(cancellationToken))
{
_logger.LogInformation("Scheduled Task is starting");
diff --git a/ConfusedPolarBear.Plugin.IntroSkipper/ScheduledTasks/DetectIntrosTask.cs b/ConfusedPolarBear.Plugin.IntroSkipper/ScheduledTasks/DetectIntrosTask.cs
index c08fced..d7b17b1 100644
--- a/ConfusedPolarBear.Plugin.IntroSkipper/ScheduledTasks/DetectIntrosTask.cs
+++ b/ConfusedPolarBear.Plugin.IntroSkipper/ScheduledTasks/DetectIntrosTask.cs
@@ -77,7 +77,7 @@ public class DetectIntrosTask : IScheduledTask
Entrypoint.CancelAutomaticTask(cancellationToken);
}
- using (ScheduledTaskSemaphore.Acquire(-1, cancellationToken))
+ using (ScheduledTaskSemaphore.Acquire(cancellationToken))
{
_logger.LogInformation("Scheduled Task is starting");
diff --git a/ConfusedPolarBear.Plugin.IntroSkipper/ScheduledTasks/ScheduledTaskSemaphore.cs b/ConfusedPolarBear.Plugin.IntroSkipper/ScheduledTasks/ScheduledTaskSemaphore.cs
index 5f6c31a..d89bbed 100644
--- a/ConfusedPolarBear.Plugin.IntroSkipper/ScheduledTasks/ScheduledTaskSemaphore.cs
+++ b/ConfusedPolarBear.Plugin.IntroSkipper/ScheduledTasks/ScheduledTaskSemaphore.cs
@@ -7,29 +7,18 @@ internal sealed class ScheduledTaskSemaphore : IDisposable
{
private static readonly SemaphoreSlim _semaphore = new(1, 1);
- private static bool _isHeld;
-
private ScheduledTaskSemaphore()
{
}
- public static int CurrentCount => _semaphore.CurrentCount;
-
- public static IDisposable Acquire(int timeout, CancellationToken cancellationToken)
+ public static IDisposable Acquire(CancellationToken cancellationToken)
{
- _isHeld = _semaphore.Wait(timeout, cancellationToken);
+ _semaphore.Wait(cancellationToken);
return new ScheduledTaskSemaphore();
}
- ///
- /// Dispose.
- ///
public void Dispose()
{
- if (_isHeld) // Release only if acquired
- {
- _semaphore.Release();
- _isHeld = false;
- }
+ _semaphore.Release();
}
}
diff --git a/ConfusedPolarBear.Plugin.IntroSkipper/Services/Entrypoint.cs b/ConfusedPolarBear.Plugin.IntroSkipper/Services/Entrypoint.cs
index 6d2363c..12721ca 100644
--- a/ConfusedPolarBear.Plugin.IntroSkipper/Services/Entrypoint.cs
+++ b/ConfusedPolarBear.Plugin.IntroSkipper/Services/Entrypoint.cs
@@ -247,7 +247,7 @@ public sealed class Entrypoint : IHostedService, IDisposable
_autoTaskCompletEvent.Reset();
using (_cancellationTokenSource = new CancellationTokenSource())
- using (ScheduledTaskSemaphore.Acquire(-1, _cancellationTokenSource.Token))
+ using (ScheduledTaskSemaphore.Acquire(_cancellationTokenSource.Token))
{
var seasonIds = new HashSet(_seasonsToAnalyze);
_seasonsToAnalyze.Clear();