use new Lock type for explicit synchronization

This commit is contained in:
13xforever 2024-11-13 14:04:54 +05:00
parent d4e78d1b1b
commit a9ff00f80e
No known key found for this signature in database
GPG Key ID: 2B2A36B482FE70C5
3 changed files with 6 additions and 3 deletions

View File

@ -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>kot(to)?)|(?<doggo>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)]; } }

View File

@ -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)

View File

@ -2,13 +2,14 @@
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Threading;
namespace CompatBot.Utils;
internal class FixedLengthBuffer<TKey, TValue>: IList<TValue>
where TKey: notnull
{
internal readonly object SyncObj = new();
internal readonly Lock SyncObj = new();
public FixedLengthBuffer(Func<TValue, TKey> keyGenerator)
{