Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/Discord.Net.Commands/Map/CommandMapNode.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.Collections.Immutable;
using System.Threading;

namespace Discord.Commands
{
Expand All @@ -11,7 +12,7 @@ internal class CommandMapNode

private readonly ConcurrentDictionary<string, CommandMapNode> _nodes;
private readonly string _name;
private readonly object _lockObj = new object();
private readonly Lock _lockObj = new();
private ImmutableArray<CommandInfo> _commands;

public bool IsEmpty => _commands.Length == 0 && _nodes.Count == 0;
Expand Down
4 changes: 4 additions & 0 deletions src/Discord.Net.Core/Discord.Net.Core.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,9 @@
<PackageReference Include="IDisposableAnalyzers" Version="4.0.8">
<PrivateAssets>all</PrivateAssets>
</PackageReference>
<PackageReference Condition="!$([MSBuild]::IsTargetFrameworkCompatible('$(TargetFramework)', 'net9.0'))" Include="Backport.System.Threading.Lock" Version="3.1.5">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>analyzers</IncludeAssets>
</PackageReference>
</ItemGroup>
</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;

using Model = Discord.API.Interaction;
Expand Down Expand Up @@ -32,7 +33,7 @@ public ulong CommandId
/// </summary>
internal new RestCommandBaseData Data { get; private set; }

private object _lock = new object();
private readonly Lock _lock = new();

internal RestCommandBase(DiscordRestClient client, Model model)
: base(client, model.Id)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
using System.IO;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using DataModel = Discord.API.MessageComponentInteractionData;
using Model = Discord.API.Interaction;
Expand All @@ -24,7 +25,7 @@ public class RestMessageComponent : RestInteraction, IComponentInteraction, IDis
/// <inheritdoc cref="IComponentInteraction.Message"/>
public RestUserMessage Message { get; private set; }

private object _lock = new object();
private readonly Lock _lock = new();

internal RestMessageComponent(BaseDiscordClient client, Model model)
: base(client, model.Id)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
using System.IO;
using System.Linq;
using System.Reflection;
using System.Threading;
using System.Threading.Tasks;

using DataModel = Discord.API.ModalInteractionData;
Expand Down Expand Up @@ -41,7 +42,7 @@ internal RestModal(DiscordRestClient client, ModelBase model)
return entity;
}

private object _lock = new object();
private readonly Lock _lock = new();

/// <summary>
/// Acknowledges this interaction with the <see cref="InteractionResponseType.DeferredUpdateMessage"/> if the modal was created
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using System.IO;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using DataModel = Discord.API.AutocompleteInteractionData;
using Model = Discord.API.Interaction;
Expand All @@ -19,7 +20,7 @@ public class RestAutocompleteInteraction : RestInteraction, IAutocompleteInterac
/// </summary>
public new RestAutocompleteInteractionData Data { get; }

private object _lock = new object();
private readonly Lock _lock = new();

internal RestAutocompleteInteraction(DiscordRestClient client, Model model)
: base(client, model.Id)
Expand Down
4 changes: 2 additions & 2 deletions src/Discord.Net.Rest/Net/Queue/RequestQueueBucket.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ internal class RequestBucket
{
private const int MinimumSleepTimeMs = 750;

private readonly object _lock;
private readonly Lock _lock;
private readonly RequestQueue _queue;
private int _semaphore;
private DateTimeOffset? _resetTick;
Expand All @@ -32,7 +32,7 @@ public RequestBucket(RequestQueue queue, IRequest request, BucketId id)
_queue = queue;
Id = id;

_lock = new object();
_lock = new();

if (request.Options.IsClientBucket)
WindowCount = ClientBucket.Get(request.Options.BucketId).WindowCount;
Expand Down
4 changes: 2 additions & 2 deletions src/Discord.Net.WebSocket/DiscordShardedClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public partial class DiscordShardedClient : BaseSocketClient, IDiscordClient
private ImmutableArray<StickerPack<SocketSticker>> _defaultStickers;
private int _totalShards;
private SemaphoreSlim[] _identifySemaphores;
private object _semaphoreResetLock;
private readonly Lock _semaphoreResetLock;
private Task _semaphoreResetTask;

private bool _isDisposed;
Expand Down Expand Up @@ -80,7 +80,7 @@ private DiscordShardedClient(int[] ids, DiscordSocketConfig config, API.DiscordS
if (ids != null && config.TotalShards == null)
throw new ArgumentException($"Custom ids are not supported when {nameof(config.TotalShards)} is not specified.");

_semaphoreResetLock = new object();
_semaphoreResetLock = new();
_shardIdsToIndex = new Dictionary<int, int>();
config.DisplayInitialLog = false;
_baseConfig = config;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
using Model = Discord.API.Channel;
using ThreadMember = Discord.API.ThreadMember;
Expand Down Expand Up @@ -110,8 +111,8 @@ public bool IsPrivateThread

private bool _usersDownloaded;

private readonly object _downloadLock = new object();
private readonly object _ownerLock = new object();
private readonly Lock _downloadLock = new();
private readonly Lock _ownerLock = new();

private ulong _ownerId;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
using DataModel = Discord.API.MessageComponentInteractionData;
using Model = Discord.API.Interaction;
Expand All @@ -24,7 +25,7 @@ public class SocketMessageComponent : SocketInteraction, IComponentInteraction,
/// <inheritdoc cref="IComponentInteraction.Message"/>
public SocketUserMessage Message { get; private set; }

private object _lock = new object();
private readonly Lock _lock = new();
public override bool HasResponded { get; internal set; } = false;

internal SocketMessageComponent(DiscordSocketClient client, Model model, ISocketMessageChannel channel, SocketUser user)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
using System.IO;
using System.Linq;
using System.Reflection;
using System.Threading;
using System.Threading.Tasks;

using DataModel = Discord.API.ModalInteractionData;
Expand Down Expand Up @@ -66,7 +67,7 @@ internal SocketModal(DiscordSocketClient client, ModelBase model, ISocketMessage

/// <inheritdoc/>
public override bool HasResponded { get; internal set; }
private object _lock = new object();
private readonly Lock _lock = new();

/// <inheritdoc/>
public override async Task RespondWithFilesAsync(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Threading;
using System.Threading.Tasks;
using DataModel = Discord.API.AutocompleteInteractionData;
using Model = Discord.API.Interaction;
Expand All @@ -21,7 +22,7 @@ public class SocketAutocompleteInteraction : SocketInteraction, IAutocompleteInt
/// <inheritdoc/>
public override bool HasResponded { get; internal set; }

private object _lock = new object();
private readonly Lock _lock = new();

internal SocketAutocompleteInteraction(DiscordSocketClient client, Model model, ISocketMessageChannel channel, SocketUser user)
: base(client, model.Id, channel, user)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
using DataModel = Discord.API.ApplicationCommandInteractionData;
using Model = Discord.API.Interaction;
Expand Down Expand Up @@ -35,7 +36,7 @@ public ulong CommandId
/// <inheritdoc/>
public override bool HasResponded { get; internal set; }

private object _lock = new object();
private readonly Lock _lock = new();

internal SocketCommandBase(DiscordSocketClient client, Model model, ISocketMessageChannel channel, SocketUser user)
: base(client, model.Id, channel, user)
Expand Down
3 changes: 2 additions & 1 deletion src/Discord.Net.WebSocket/Entities/Users/SocketGlobalUser.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using System;
using System.Diagnostics;
using System.Linq;
using System.Threading;
using Model = Discord.API.User;

namespace Discord.WebSocket
Expand Down Expand Up @@ -31,7 +32,7 @@ internal class SocketGlobalUser : SocketUser
/// <inheritdoc />
internal override SocketGlobalUser GlobalUser { get => this; set => throw new NotImplementedException(); }

private readonly object _lockObj = new object();
private readonly Lock _lockObj = new();
private ushort _references;

private SocketGlobalUser(DiscordSocketClient discord, ulong id)
Expand Down