Skip to content

Commit

Permalink
use new Lock type for explicit synchronization
Browse files Browse the repository at this point in the history
  • Loading branch information
13xforever committed Nov 13, 2024
1 parent d4e78d1 commit a9ff00f
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 3 deletions.
3 changes: 2 additions & 1 deletion CompatBot/EventHandlers/BotReactionsHandler.cs
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -72,7 +73,7 @@ internal static partial class BotReactionsHandler
[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)]; } }
Expand Down
3 changes: 2 additions & 1 deletion CompatBot/Utils/BufferCopyStream.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using System;
using System.Buffers;
using System.IO;
using System.Threading;

namespace CompatBot.Utils;

Expand All @@ -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)
Expand Down
3 changes: 2 additions & 1 deletion CompatBot/Utils/FixedLengthBuffer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down

0 comments on commit a9ff00f

Please sign in to comment.