From a9ff00f80e75b35bfa49cf4ad89ab16cff2338b0 Mon Sep 17 00:00:00 2001 From: 13xforever Date: Wed, 13 Nov 2024 14:04:54 +0500 Subject: [PATCH] use new Lock type for explicit synchronization --- CompatBot/EventHandlers/BotReactionsHandler.cs | 3 ++- CompatBot/Utils/BufferCopyStream.cs | 3 ++- CompatBot/Utils/FixedLengthBuffer.cs | 3 ++- 3 files changed, 6 insertions(+), 3 deletions(-) diff --git a/CompatBot/EventHandlers/BotReactionsHandler.cs b/CompatBot/EventHandlers/BotReactionsHandler.cs index 8ec894a6..a5bb416e 100644 --- a/CompatBot/EventHandlers/BotReactionsHandler.cs +++ b/CompatBot/EventHandlers/BotReactionsHandler.cs @@ -1,6 +1,7 @@ using System; using System.Linq; using System.Text.RegularExpressions; +using System.Threading; using System.Threading.Tasks; using CompatBot.Commands.Attributes; using CompatBot.Database; @@ -72,7 +73,7 @@ namespace CompatBot.EventHandlers [GeneratedRegex(@"\b((?kot(to)?)|(?doggo|jarves))\b", RegexOptions.IgnoreCase | RegexOptions.Singleline | RegexOptions.ExplicitCapture)] private static partial Regex Paws(); private static readonly Random Rng = new(); - private static readonly object TheDoor = new(); + private static readonly Lock TheDoor = new(); public static DiscordEmoji RandomNegativeReaction { get { lock (TheDoor) return SadReactions[Rng.Next(SadReactions.Length)]; } } public static DiscordEmoji RandomPositiveReaction { get { lock (TheDoor) return ThankYouReactions[Rng.Next(ThankYouReactions.Length)]; } } diff --git a/CompatBot/Utils/BufferCopyStream.cs b/CompatBot/Utils/BufferCopyStream.cs index 46a89834..8a8c8a5f 100644 --- a/CompatBot/Utils/BufferCopyStream.cs +++ b/CompatBot/Utils/BufferCopyStream.cs @@ -1,6 +1,7 @@ using System; using System.Buffers; using System.IO; +using System.Threading; namespace CompatBot.Utils; @@ -14,7 +15,7 @@ internal class BufferCopyStream : Stream, IDisposable private readonly byte[] writeBuf; private readonly byte[] readBuf; private int bufStart, bufLength; - private readonly object sync = new(); + private readonly Lock sync = new(); private bool disposed; public BufferCopyStream(Stream? baseStream, int bufferSize = 4096) diff --git a/CompatBot/Utils/FixedLengthBuffer.cs b/CompatBot/Utils/FixedLengthBuffer.cs index cc4b9005..0971d3a0 100644 --- a/CompatBot/Utils/FixedLengthBuffer.cs +++ b/CompatBot/Utils/FixedLengthBuffer.cs @@ -2,13 +2,14 @@ using System.Collections; using System.Collections.Generic; using System.Linq; +using System.Threading; namespace CompatBot.Utils; internal class FixedLengthBuffer: IList where TKey: notnull { - internal readonly object SyncObj = new(); + internal readonly Lock SyncObj = new(); public FixedLengthBuffer(Func keyGenerator) {