aboutsummaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorLibravatar vnugent <public@vaughnnugent.com>2023-04-13 11:44:19 -0400
committerLibravatar vnugent <public@vaughnnugent.com>2023-04-13 11:44:19 -0400
commitbaf859f45cf1f00e79508954517ed4b6fb446103 (patch)
tree2c51e41e61b87f31996bc3f426ad945787e0fbbc /lib
parentde7860f1b91ec72a5d0e66aba7f7a7a04a87d038 (diff)
Record structure additions
Diffstat (limited to 'lib')
-rw-r--r--lib/Utils/src/Extensions/MutexReleaser.cs25
-rw-r--r--lib/Utils/src/Extensions/SemSlimReleaser.cs21
-rw-r--r--lib/Utils/src/Extensions/SerializerHandle.cs39
-rw-r--r--lib/Utils/src/Extensions/TimerResumeHandle.cs16
4 files changed, 16 insertions, 85 deletions
diff --git a/lib/Utils/src/Extensions/MutexReleaser.cs b/lib/Utils/src/Extensions/MutexReleaser.cs
index 84dd60f..16cc445 100644
--- a/lib/Utils/src/Extensions/MutexReleaser.cs
+++ b/lib/Utils/src/Extensions/MutexReleaser.cs
@@ -1,5 +1,5 @@
/*
-* Copyright (c) 2022 Vaughn Nugent
+* Copyright (c) 2023 Vaughn Nugent
*
* Library: VNLib
* Package: VNLib.Utils
@@ -32,31 +32,16 @@ namespace VNLib.Utils.Extensions
/// that has been entered and will be released. Best if used
/// within a using() statment
/// </summary>
- public readonly struct MutexReleaser : IDisposable, IEquatable<MutexReleaser>
+ /// <param name="Handle">The Mutext referrence</param>
+ public readonly record struct MutexReleaser(Mutex Handle) : IDisposable
{
- private readonly Mutex _mutext;
- internal MutexReleaser(Mutex mutex) => _mutext = mutex;
/// <summary>
/// Releases the held System.Threading.Mutex once.
/// </summary>
- public readonly void Dispose() => _mutext.ReleaseMutex();
+ public readonly void Dispose() => Handle.ReleaseMutex();
/// <summary>
/// Releases the held System.Threading.Mutex once.
/// </summary>
- public readonly void ReleaseMutext() => _mutext.ReleaseMutex();
-
- ///<inheritdoc/>
- public bool Equals(MutexReleaser other) => _mutext.Equals(other._mutext);
-
- ///<inheritdoc/>
- public override bool Equals(object? obj) => obj is MutexReleaser releaser && Equals(releaser);
-
- ///<inheritdoc/>
- public override int GetHashCode() => _mutext.GetHashCode();
-
- ///<inheritdoc/>
- public static bool operator ==(MutexReleaser left, MutexReleaser right) => left.Equals(right);
- ///<inheritdoc/>
- public static bool operator !=(MutexReleaser left, MutexReleaser right) => !(left == right);
+ public readonly void ReleaseMutext() => Handle.ReleaseMutex();
}
} \ No newline at end of file
diff --git a/lib/Utils/src/Extensions/SemSlimReleaser.cs b/lib/Utils/src/Extensions/SemSlimReleaser.cs
index c3be4f8..9f3a845 100644
--- a/lib/Utils/src/Extensions/SemSlimReleaser.cs
+++ b/lib/Utils/src/Extensions/SemSlimReleaser.cs
@@ -1,5 +1,5 @@
/*
-* Copyright (c) 2022 Vaughn Nugent
+* Copyright (c) 2023 Vaughn Nugent
*
* Library: VNLib
* Package: VNLib.Utils
@@ -32,31 +32,18 @@ namespace VNLib.Utils.Extensions
/// that has been entered and will be released. Best if used
/// within a using() statment
/// </summary>
- public readonly struct SemSlimReleaser : IDisposable, IEquatable<SemSlimReleaser>
+ public readonly record struct SemSlimReleaser(SemaphoreSlim Semaphore) : IDisposable
{
- private readonly SemaphoreSlim _semaphore;
- internal SemSlimReleaser(SemaphoreSlim semaphore) => _semaphore = semaphore;
/// <summary>
/// Releases the System.Threading.SemaphoreSlim object once.
/// </summary>
- public readonly void Dispose() => _semaphore.Release();
+ public readonly void Dispose() => Semaphore.Release();
/// <summary>
/// Releases the System.Threading.SemaphoreSlim object once.
/// </summary>
/// <returns>The previous count of the <see cref="SemaphoreSlim"/></returns>
/// <exception cref="ObjectDisposedException"></exception>
/// <exception cref="SemaphoreFullException"></exception>
- public readonly int Release() => _semaphore.Release();
-
- ///<inheritdoc/>
- public override bool Equals(object obj) => obj is SemSlimReleaser ssr && Equals(ssr);
- ///<inheritdoc/>
- public override int GetHashCode() => _semaphore.GetHashCode();
- ///<inheritdoc/>
- public static bool operator ==(SemSlimReleaser left, SemSlimReleaser right) => left.Equals(right);
- ///<inheritdoc/>
- public static bool operator !=(SemSlimReleaser left, SemSlimReleaser right) => !(left == right);
- ///<inheritdoc/>
- public bool Equals(SemSlimReleaser other) => _semaphore == other._semaphore;
+ public readonly int Release() => Semaphore.Release();
}
} \ No newline at end of file
diff --git a/lib/Utils/src/Extensions/SerializerHandle.cs b/lib/Utils/src/Extensions/SerializerHandle.cs
index 3d410e2..2d9d7d8 100644
--- a/lib/Utils/src/Extensions/SerializerHandle.cs
+++ b/lib/Utils/src/Extensions/SerializerHandle.cs
@@ -24,7 +24,6 @@
using System;
-
using VNLib.Utils.Async;
namespace VNLib.Utils.Extensions
@@ -34,43 +33,13 @@ namespace VNLib.Utils.Extensions
/// and releases the lock when the handle is disposed
/// </summary>
/// <typeparam name="TMoniker">The moniker type</typeparam>
- public readonly struct SerializerHandle<TMoniker> : IDisposable, IEquatable<SerializerHandle<TMoniker>>
+ /// <param name="Moniker">The monike that referrences the entered lock</param>
+ /// <param name="Serializer">The serialzer this handle will release the lock on when disposed</param>
+ public readonly record struct SerializerHandle<TMoniker>(TMoniker Moniker, IAsyncAccessSerializer<TMoniker> Serializer) : IDisposable
{
- private readonly IAsyncAccessSerializer<TMoniker> _serializer;
- private readonly TMoniker _moniker;
-
- /// <summary>
- /// Inializes a new <see cref="SerializerHandle{TMoniker}"/> that is holding
- /// a lock to the given <see cref="IAsyncAccessSerializer{TMoniker}"/> by the
- /// given <paramref name="moniker"/>
- /// </summary>
- /// <param name="moniker">The monike that referrences the entered lock</param>
- /// <param name="serializer">The serialzer this handle will release the lock on when disposed</param>
- public SerializerHandle(TMoniker moniker, IAsyncAccessSerializer<TMoniker> serializer)
- {
- _moniker = moniker;
- _serializer = serializer;
- }
-
/// <summary>
/// Releases the exclusive lock on the moinker back to the serializer;
/// </summary>
- public readonly void Dispose() => _serializer.Release(_moniker);
-
- ///<inheritdoc/>
- public override bool Equals(object? obj) => obj is SerializerHandle<TMoniker> sh && Equals(sh);
-
- ///<inheritdoc/>
- public override int GetHashCode() => _moniker?.GetHashCode() ?? 0;
-
- public static bool operator ==(SerializerHandle<TMoniker> left, SerializerHandle<TMoniker> right) => left.Equals(right);
-
- public static bool operator !=(SerializerHandle<TMoniker> left, SerializerHandle<TMoniker> right) => !(left == right);
-
- ///<inheritdoc/>
- public bool Equals(SerializerHandle<TMoniker> other)
- {
- return (_moniker == null && other._moniker == null) || _moniker != null && _moniker.Equals(other._moniker);
- }
+ public readonly void Dispose() => Serializer.Release(Moniker);
}
}
diff --git a/lib/Utils/src/Extensions/TimerResumeHandle.cs b/lib/Utils/src/Extensions/TimerResumeHandle.cs
index f386974..1f4168e 100644
--- a/lib/Utils/src/Extensions/TimerResumeHandle.cs
+++ b/lib/Utils/src/Extensions/TimerResumeHandle.cs
@@ -1,5 +1,5 @@
/*
-* Copyright (c) 2022 Vaughn Nugent
+* Copyright (c) 2023 Vaughn Nugent
*
* Library: VNLib
* Package: VNLib.Utils
@@ -31,7 +31,7 @@ namespace VNLib.Utils.Extensions
/// A handle that represents a paused timer that may be resumed when the handle is disposed
/// or the Resume() method is called
/// </summary>
- public readonly struct TimerResumeHandle: IEquatable<TimerResumeHandle>, IDisposable
+ public readonly record struct TimerResumeHandle: IDisposable
{
private readonly Timer _timer;
private readonly TimeSpan _resumeTime;
@@ -46,21 +46,11 @@ namespace VNLib.Utils.Extensions
/// Resumes the timer to the configured time from the call to Timer.Stop()
/// </summary>
public void Resume() => _timer.Change(_resumeTime, Timeout.InfiniteTimeSpan);
+
/// <summary>
/// Releases any resources held by the Handle, and resumes the timer to
/// the configured time from the call to Timer.Stop()
/// </summary>
public void Dispose() => Resume();
-
- ///<inheritdoc/>
- public bool Equals(TimerResumeHandle other) => _timer.Equals(other) && _resumeTime == other._resumeTime;
- ///<inheritdoc/>
- public override bool Equals(object? obj) => obj is TimerResumeHandle trh && Equals(trh);
- ///<inheritdoc/>
- public override int GetHashCode() => _timer.GetHashCode() + _resumeTime.GetHashCode();
- ///<inheritdoc/>
- public static bool operator ==(TimerResumeHandle left, TimerResumeHandle right) => left.Equals(right);
- ///<inheritdoc/>
- public static bool operator !=(TimerResumeHandle left, TimerResumeHandle right) => !(left == right);
}
} \ No newline at end of file