Skip to content

Commit

Permalink
Use global usings for locks
Browse files Browse the repository at this point in the history
  • Loading branch information
ltrzesniewski committed Nov 28, 2024
1 parent e80fb57 commit 390af98
Show file tree
Hide file tree
Showing 5 changed files with 9 additions and 19 deletions.
5 changes: 2 additions & 3 deletions src/ZeroLog.Benchmarks/Tools/SerilogTestSink.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using System;
using System.Collections.Generic;
using System.Collections.Generic;
using System.Threading;
using Serilog.Core;
using Serilog.Events;
Expand All @@ -9,7 +8,7 @@ namespace ZeroLog.Benchmarks.Tools;
public class SerilogTestSink : ILogEventSink
{
private readonly bool _captureLoggedMessages;
private readonly object _lock = new();
private readonly Lock _lock = new();
private int _messageCount;
private ManualResetEventSlim _signal;
private int _messageCountTarget;
Expand Down
7 changes: 1 addition & 6 deletions src/ZeroLog.Impl.Full/BufferSegmentProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,7 @@ namespace ZeroLog;

internal unsafe class BufferSegmentProvider
{
#if NET9_0_OR_GREATER
private readonly System.Threading.Lock _lock = new();
#else
private readonly object _lock = new();
#endif

private readonly Lock _lock = new();
private readonly int _segmentCount;
private readonly int _segmentSize;

Expand Down
5 changes: 5 additions & 0 deletions src/ZeroLog.Impl.Full/GlobalUsings.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#if NET9_0_OR_GREATER
global using Lock = System.Threading.Lock;
#else
global using Lock = System.Object;
#endif
4 changes: 0 additions & 4 deletions src/ZeroLog.Impl.Full/Runner.cs
Original file line number Diff line number Diff line change
Expand Up @@ -310,11 +310,7 @@ public override void Flush()

internal sealed class SyncRunner(ZeroLogConfiguration config) : Runner(config)
{
#if NET9_0_OR_GREATER
private readonly Lock _lock = new();
#else
private readonly object _lock = new();
#endif

public override void Submit(LogMessage message)
{
Expand Down
7 changes: 1 addition & 6 deletions src/ZeroLog.Impl.Full/UnmanagedCache.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,7 @@ internal delegate bool FormatterDelegate(
ZeroLogConfiguration config
);

#if NET9_0_OR_GREATER
private static readonly System.Threading.Lock _lock = new();
#else
private static readonly object _lock = new();
#endif

private static readonly Lock _lock = new();
private static readonly Dictionary<IntPtr, FormatterDelegate> _unmanagedStructs = new();
private static readonly MethodInfo _registerMethod = typeof(UnmanagedCache).GetMethod(nameof(Register), Type.EmptyTypes)!;

Expand Down

0 comments on commit 390af98

Please sign in to comment.