Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 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
6 changes: 6 additions & 0 deletions GlobalUsings.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
// These are used in all projects except samples.

// Use the new System.Threading.Lock type on .NET 9+, which enables compiler optimisations.
// On earlier targets, alias it to object so the same lock pattern works everywhere.
#if !NET9_0_OR_GREATER
global using Lock = object;
#endif

global using System.Buffers;
global using System.Collections;
global using System.Collections.Concurrent;
Expand Down
2 changes: 1 addition & 1 deletion src/Sentry.Log4Net/SentryAppender.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ public class SentryAppender : AppenderSkeleton
private readonly Func<string, IDisposable> _initAction;
private volatile IDisposable? _sdkHandle;

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

internal static readonly SdkVersion NameAndVersion
= typeof(SentryAppender).Assembly.GetNameAndVersion();
Expand Down
4 changes: 1 addition & 3 deletions src/Sentry.Maui/Internal/MauiDeviceData.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,8 @@ namespace Sentry.Maui.Internal;

internal static class MauiDeviceData
{
#if NET9_0_OR_GREATER && ANDROID
#if ANDROID
private static readonly Lock JniLock = new();
#elif ANDROID
private static readonly object JniLock = new();
#endif

public static void ApplyMauiDeviceData(this Device device, IDiagnosticLogger? logger,
Expand Down
4 changes: 1 addition & 3 deletions src/Sentry.Maui/Internal/ScreenshotAttachment.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,8 @@ internal class ScreenshotAttachmentContent : IAttachmentContent
{
private readonly SentryMauiOptions _options;

#if NET9_0_OR_GREATER && ANDROID
#if ANDROID
private static readonly Lock JniLock = new();
#elif ANDROID
private static readonly object JniLock = new();
#endif

public ScreenshotAttachmentContent(SentryMauiOptions options)
Expand Down
2 changes: 1 addition & 1 deletion src/Sentry/Internal/Hub.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ namespace Sentry.Internal;

internal class Hub : IHub, IDisposable
{
private readonly object _sessionPauseLock = new();
private readonly Lock _sessionPauseLock = new();

private readonly ISystemClock _clock;
private readonly ISessionManager _sessionManager;
Expand Down
2 changes: 1 addition & 1 deletion src/Sentry/Internal/InstallationIdHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ namespace Sentry.Internal;

internal class InstallationIdHelper(SentryOptions options)
{
private readonly object _installationIdLock = new();
private readonly Lock _installationIdLock = new();
private string? _installationId;

public string? TryGetInstallationId()
Expand Down
2 changes: 1 addition & 1 deletion src/Sentry/Internal/Signal.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ namespace Sentry.Internal;

internal class Signal : IDisposable
{
private readonly object _lock = new();
private readonly Lock _lock = new();
private readonly SemaphoreSlim _semaphore = new(0, 1);

public Signal(bool isReleasedInitially = false)
Expand Down
4 changes: 2 additions & 2 deletions src/Sentry/Scope.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public class Scope : IEventLike

internal bool Locked { get; set; }

private readonly object _lastEventIdSync = new();
private readonly Lock _lastEventIdSync = new();
private SentryId _lastEventId;

internal SentryId LastEventId
Expand All @@ -43,7 +43,7 @@ internal SentryId LastEventId
}
}

private readonly object _evaluationSync = new();
private readonly Lock _evaluationSync = new();
private volatile bool _hasEvaluated;

/// <summary>
Expand Down
2 changes: 1 addition & 1 deletion src/Sentry/SentryMessageHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ public abstract class SentryMessageHandler : DelegatingHandler
{
private readonly IHub _hub;
private readonly SentryOptions? _options;
private readonly object _innerHandlerLock = new();
private readonly Lock _innerHandlerLock = new();

/// <summary>
/// Constructs an instance of <see cref="SentryMessageHandler"/>.
Expand Down
2 changes: 1 addition & 1 deletion src/Sentry/TransactionTracer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -316,7 +316,7 @@ private void AddChildSpan(SpanTracer span)

private class LastActiveSpanTracker
{
private readonly object _lock = new object();
private readonly Lock _lock = new();

private readonly Lazy<Stack<ISpan>> _trackedSpans = new();
private Stack<ISpan> TrackedSpans => _trackedSpans.Value;
Expand Down
2 changes: 1 addition & 1 deletion test/Sentry.Maui.Tests/Mocks/MockApplication.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ namespace Sentry.Maui.Tests.Mocks;

public class MockApplication : Application
{
private static readonly object LockObj = new();
private static readonly Lock LockObj = new();
private Page _mainPage;

static MockApplication()
Expand Down
Loading