[backend] Use SemaphorePlus instead of SemaphoreSlim

This commit is contained in:
Laura Hausmann 2024-07-22 05:59:41 +02:00
parent 7ea2f71abe
commit c7d0280eb6
No known key found for this signature in database
GPG key ID: D044E84C5BE01605
2 changed files with 3 additions and 2 deletions

View file

@ -25,7 +25,7 @@ public sealed class WebSocketConnection(
{ {
private readonly WriteLockingList<string> _blockedBy = []; private readonly WriteLockingList<string> _blockedBy = [];
private readonly WriteLockingList<string> _blocking = []; private readonly WriteLockingList<string> _blocking = [];
private readonly SemaphoreSlim _lock = new(1); private readonly SemaphorePlus _lock = new(1);
private readonly WriteLockingList<string> _muting = []; private readonly WriteLockingList<string> _muting = [];
public readonly List<IChannel> Channels = []; public readonly List<IChannel> Channels = [];
public readonly EventService EventService = eventSvc; public readonly EventService EventService = eventSvc;

View file

@ -1,5 +1,6 @@
using System.Net; using System.Net;
using Iceshrimp.Backend.Core.Configuration; using Iceshrimp.Backend.Core.Configuration;
using Iceshrimp.Backend.Core.Helpers;
using Microsoft.Extensions.Options; using Microsoft.Extensions.Options;
namespace Iceshrimp.Backend.Core.Middleware; namespace Iceshrimp.Backend.Core.Middleware;
@ -9,7 +10,7 @@ public class FederationSemaphoreMiddleware(
IHostApplicationLifetime appLifetime IHostApplicationLifetime appLifetime
) : IMiddleware ) : IMiddleware
{ {
private readonly SemaphoreSlim _semaphore = new(config.Value.FederationRequestHandlerConcurrency); private readonly SemaphorePlus _semaphore = new(Math.Max(config.Value.FederationRequestHandlerConcurrency, 1));
public async Task InvokeAsync(HttpContext ctx, RequestDelegate next) public async Task InvokeAsync(HttpContext ctx, RequestDelegate next)
{ {