Skip to content

Commit b386a0e

Browse files
authored
Switch lock backport package to #if defs instead (#3217)
1 parent 4e95dd7 commit b386a0e

File tree

14 files changed

+60
-11
lines changed

14 files changed

+60
-11
lines changed

src/Discord.Net.Commands/Map/CommandMapNode.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,11 @@ internal class CommandMapNode
1212

1313
private readonly ConcurrentDictionary<string, CommandMapNode> _nodes;
1414
private readonly string _name;
15+
#if NET9_0_OR_GREATER
1516
private readonly Lock _lockObj = new();
17+
#else
18+
private readonly object _lockObj = new();
19+
#endif
1620
private ImmutableArray<CommandInfo> _commands;
1721

1822
public bool IsEmpty => _commands.Length == 0 && _nodes.Count == 0;

src/Discord.Net.Core/Discord.Net.Core.csproj

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,5 @@
1919
<PackageReference Include="IDisposableAnalyzers" Version="4.0.8">
2020
<PrivateAssets>all</PrivateAssets>
2121
</PackageReference>
22-
<PackageReference Condition="!$([MSBuild]::IsTargetFrameworkCompatible('$(TargetFramework)', 'net9.0'))" Include="Backport.System.Threading.Lock" Version="3.1.5">
23-
<PrivateAssets>all</PrivateAssets>
24-
<IncludeAssets>analyzers</IncludeAssets>
25-
</PackageReference>
2622
</ItemGroup>
27-
</Project>
23+
</Project>

src/Discord.Net.Rest/Entities/Interactions/CommandBase/RestCommandBase.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,11 @@ public ulong CommandId
3333
/// </summary>
3434
internal new RestCommandBaseData Data { get; private set; }
3535

36+
#if NET9_0_OR_GREATER
3637
private readonly Lock _lock = new();
38+
#else
39+
private readonly object _lock = new();
40+
#endif
3741

3842
internal RestCommandBase(DiscordRestClient client, Model model)
3943
: base(client, model.Id)

src/Discord.Net.Rest/Entities/Interactions/MessageComponents/RestMessageComponent.cs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,11 @@ public class RestMessageComponent : RestInteraction, IComponentInteraction, IDis
2525
/// <inheritdoc cref="IComponentInteraction.Message"/>
2626
public RestUserMessage Message { get; private set; }
2727

28+
#if NET9_0_OR_GREATER
2829
private readonly Lock _lock = new();
30+
#else
31+
private readonly object _lock = new();
32+
#endif
2933

3034
internal RestMessageComponent(BaseDiscordClient client, Model model)
3135
: base(client, model.Id)
@@ -457,7 +461,7 @@ public string DeferLoading(bool ephemeral = false, RequestOptions options = null
457461
}
458462

459463
/// <summary>
460-
///
464+
///
461465
/// </summary>
462466
/// <param name="ephemeral"></param>
463467
/// <param name="options"></param>

src/Discord.Net.Rest/Entities/Interactions/Modals/RestModal.cs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,11 @@ internal RestModal(DiscordRestClient client, ModelBase model)
4242
return entity;
4343
}
4444

45+
#if NET9_0_OR_GREATER
4546
private readonly Lock _lock = new();
47+
#else
48+
private readonly object _lock = new();
49+
#endif
4650

4751
/// <summary>
4852
/// Acknowledges this interaction with the <see cref="InteractionResponseType.DeferredUpdateMessage"/> if the modal was created
@@ -139,7 +143,7 @@ public override Task<RestFollowupMessage> FollowupAsync(
139143
MessageComponent component = null,
140144
Embed embed = null,
141145
RequestOptions options = null,
142-
PollProperties poll = null,
146+
PollProperties poll = null,
143147
MessageFlags flags = MessageFlags.None)
144148
{
145149
if (!IsValidToken)

src/Discord.Net.Rest/Entities/Interactions/SlashCommands/RestAutocompleteInteraction.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,11 @@ public class RestAutocompleteInteraction : RestInteraction, IAutocompleteInterac
2020
/// </summary>
2121
public new RestAutocompleteInteractionData Data { get; }
2222

23+
#if NET9_0_OR_GREATER
2324
private readonly Lock _lock = new();
25+
#else
26+
private readonly object _lock = new();
27+
#endif
2428

2529
internal RestAutocompleteInteraction(DiscordRestClient client, Model model)
2630
: base(client, model.Id)

src/Discord.Net.Rest/Net/Queue/RequestQueueBucket.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,11 @@ internal class RequestBucket
1717
{
1818
private const int MinimumSleepTimeMs = 750;
1919

20+
#if NET9_0_OR_GREATER
2021
private readonly Lock _lock;
22+
#else
23+
private readonly object _lock;
24+
#endif
2125
private readonly RequestQueue _queue;
2226
private int _semaphore;
2327
private DateTimeOffset? _resetTick;

src/Discord.Net.WebSocket/DiscordShardedClient.cs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,11 @@ public partial class DiscordShardedClient : BaseSocketClient, IDiscordClient
2121
private ImmutableArray<StickerPack<SocketSticker>> _defaultStickers;
2222
private int _totalShards;
2323
private SemaphoreSlim[] _identifySemaphores;
24+
#if NET9_0_OR_GREATER
2425
private readonly Lock _semaphoreResetLock;
26+
#else
27+
private readonly object _semaphoreResetLock;
28+
#endif
2529
private Task _semaphoreResetTask;
2630

2731
private bool _isDisposed;
@@ -524,7 +528,7 @@ private void RegisterEvents(DiscordSocketClient client, bool isPrimary)
524528
client.AuditLogCreated += (arg1, arg2) => _auditLogCreated.InvokeAsync(arg1, arg2);
525529

526530
client.VoiceChannelStatusUpdated += (arg1, arg2, arg3) => _voiceChannelStatusUpdated.InvokeAsync(arg1, arg2, arg3);
527-
531+
528532
client.EntitlementCreated += (arg1) => _entitlementCreated.InvokeAsync(arg1);
529533
client.EntitlementUpdated += (arg1, arg2) => _entitlementUpdated.InvokeAsync(arg1, arg2);
530534
client.EntitlementDeleted += (arg1) => _entitlementDeleted.InvokeAsync(arg1);

src/Discord.Net.WebSocket/Entities/Channels/SocketThreadChannel.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,8 +111,13 @@ public bool IsPrivateThread
111111

112112
private bool _usersDownloaded;
113113

114+
#if NET9_0_OR_GREATER
114115
private readonly Lock _downloadLock = new();
115116
private readonly Lock _ownerLock = new();
117+
#else
118+
private readonly object _downloadLock = new();
119+
private readonly object _ownerLock = new();
120+
#endif
116121

117122
private ulong _ownerId;
118123

src/Discord.Net.WebSocket/Entities/Interaction/MessageComponents/SocketMessageComponent.cs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,15 @@ public class SocketMessageComponent : SocketInteraction, IComponentInteraction,
2121
/// Gets the data received with this interaction, contains the button that was clicked.
2222
/// </summary>
2323
public new SocketMessageComponentData Data { get; }
24-
24+
2525
/// <inheritdoc cref="IComponentInteraction.Message"/>
2626
public SocketUserMessage Message { get; private set; }
2727

28+
#if NET9_0_OR_GREATER
2829
private readonly Lock _lock = new();
30+
#else
31+
private readonly object _lock = new();
32+
#endif
2933
public override bool HasResponded { get; internal set; } = false;
3034

3135
internal SocketMessageComponent(DiscordSocketClient client, Model model, ISocketMessageChannel channel, SocketUser user)
@@ -359,7 +363,7 @@ public override Task<RestFollowupMessage> FollowupAsync(
359363
flags |= MessageFlags.Ephemeral;
360364

361365
Preconditions.ValidateMessageFlags(flags);
362-
366+
363367

364368
var args = new API.Rest.CreateWebhookMessageParams
365369
{

0 commit comments

Comments
 (0)