Skip to content

Commit

Permalink
Threading 5.5.0
Browse files Browse the repository at this point in the history
  • Loading branch information
sakno committed Jun 7, 2024
1 parent cacf3e5 commit f63a24c
Show file tree
Hide file tree
Showing 5 changed files with 64 additions and 20 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
Release Notes
====

# 06-07-2024
<a href="https://www.nuget.org/packages/dotnext.threading/5.5.0">DotNext.Metaprogramming 5.5.0</a>
* Fixed [240](https://github.com/dotnet/dotNext/issues/240)

# 05-30-2024
<a href="https://www.nuget.org/packages/dotnext.threading/5.4.1">DotNext.Metaprogramming 5.4.1</a>
* Smallish performance improvements for all synchronization primitives
Expand Down
12 changes: 3 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,16 +44,10 @@ All these things are implemented in 100% managed code on top of existing .NET AP
* [NuGet Packages](https://www.nuget.org/profiles/rvsakno)

# What's new
Release Date: 05-30-2024
Release Date: 06-07-2024

<a href="https://www.nuget.org/packages/dotnext.threading/5.4.1">DotNext.Metaprogramming 5.4.1</a>
* Smallish performance improvements for all synchronization primitives

<a href="https://www.nuget.org/packages/dotnext.net.cluster/5.6.0">DotNext.Net.Cluster 5.6.0</a>
* Added support of custom data to be passed to `PersistentState.ApplyAsync` method through WAL processing pipeline

<a href="https://www.nuget.org/packages/dotnext.aspnetcore.cluster/5.6.0">DotNext.AspNetCore.Cluster 5.6.0</a>
* Updated dependencies
<a href="https://www.nuget.org/packages/dotnext.threading/5.5.0">DotNext.Metaprogramming 5.5.0</a>
* Fixed [240](https://github.com/dotnet/dotNext/issues/240)

Changelog for previous versions located [here](./CHANGELOG.md).

Expand Down
2 changes: 1 addition & 1 deletion src/DotNext.Threading/DotNext.Threading.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<ImplicitUsings>true</ImplicitUsings>
<IsTrimmable>true</IsTrimmable>
<Features>nullablePublicOnly</Features>
<VersionPrefix>5.4.1</VersionPrefix>
<VersionPrefix>5.5.0</VersionPrefix>
<VersionSuffix></VersionSuffix>
<Authors>.NET Foundation and Contributors</Authors>
<Product>.NEXT Family of Libraries</Product>
Expand Down
4 changes: 3 additions & 1 deletion src/DotNext.Threading/Threading/AsyncLock.cs
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,9 @@ public readonly async ValueTask<Holder> AcquireAsync(TimeSpan timeout, Cancellat
task = As<AsyncReaderWriterLock>(lockedObject).UpgradeToWriteLockAsync(timeout, token);
break;
case Type.Semaphore:
task = CheckOnTimeoutAsync(As<SemaphoreSlim>(lockedObject).WaitAsync(timeout, token));
task = timeout == InfiniteTimeSpan
? new(As<SemaphoreSlim>(lockedObject).WaitAsync(token))
: CheckOnTimeoutAsync(As<SemaphoreSlim>(lockedObject).WaitAsync(timeout, token));
break;
case Type.Strong:
task = As<AsyncSharedLock>(lockedObject).AcquireAsync(true, timeout, token);
Expand Down
62 changes: 53 additions & 9 deletions src/DotNext.Threading/Threading/AsyncLockAcquisition.cs
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,9 @@ private static AsyncLock GetExclusiveLock<T>(this T obj)
/// <param name="timeout">The interval to wait for the lock.</param>
/// <returns>The acquired lock holder.</returns>
/// <exception cref="TimeoutException">The lock cannot be acquired during the specified amount of time.</exception>
public static ValueTask<AsyncLock.Holder> AcquireLockAsync<T>(this T obj, TimeSpan timeout)
where T : class => obj.GetExclusiveLock().AcquireAsync(timeout);
[Obsolete("Use AcquireLockAsync(T, TimeSpan, CancellationToken) overload instead.", error: true)]
public static ValueTask<AsyncLock.Holder> AcquireLockAsync<T>(T obj, TimeSpan timeout)
where T : class => AcquireLockAsync(obj, timeout, CancellationToken.None);

/// <summary>
/// Acquires exclusive lock associated with the given object.
Expand All @@ -79,9 +80,23 @@ private static AsyncLock GetExclusiveLock<T>(this T obj)
/// <param name="obj">The object to be locked.</param>
/// <param name="token">The token that can be used to abort acquisition operation.</param>
/// <returns>The acquired lock holder.</returns>
public static ValueTask<AsyncLock.Holder> AcquireLockAsync<T>(this T obj, CancellationToken token)
/// <exception cref="OperationCanceledException">The operation has been canceled.</exception>
public static ValueTask<AsyncLock.Holder> AcquireLockAsync<T>(this T obj, CancellationToken token = default)
where T : class => obj.GetExclusiveLock().AcquireAsync(token);

/// <summary>
/// Acquires exclusive lock associated with the given object.
/// </summary>
/// <typeparam name="T">The type of the object to be locked.</typeparam>
/// <param name="obj">The object to be locked.</param>
/// <param name="timeout">The interval to wait for the lock.</param>
/// <param name="token">The token that can be used to abort acquisition operation.</param>
/// <returns>The acquired lock holder.</returns>
/// <exception cref="OperationCanceledException">The operation has been canceled.</exception>
/// <exception cref="TimeoutException">The lock cannot be acquired during the specified amount of time.</exception>
public static ValueTask<AsyncLock.Holder> AcquireLockAsync<T>(this T obj, TimeSpan timeout, CancellationToken token = default)
where T : class => obj.GetExclusiveLock().AcquireAsync(timeout, token);

/// <summary>
/// Acquires reader lock associated with the given object.
/// </summary>
Expand All @@ -90,8 +105,9 @@ private static AsyncLock GetExclusiveLock<T>(this T obj)
/// <param name="timeout">The interval to wait for the lock.</param>
/// <returns>The acquired lock holder.</returns>
/// <exception cref="TimeoutException">The lock cannot be acquired during the specified amount of time.</exception>
public static ValueTask<AsyncLock.Holder> AcquireReadLockAsync<T>(this T obj, TimeSpan timeout)
where T : class => AsyncLock.ReadLock(obj.GetReaderWriterLock()).AcquireAsync(timeout);
[Obsolete("Use AcquireReadLockAsync(T, TimeSpan, CancellationToken) overload instead.", error: true)]
public static ValueTask<AsyncLock.Holder> AcquireReadLockAsync<T>(T obj, TimeSpan timeout)
where T : class => AcquireReadLockAsync(obj, timeout, CancellationToken.None);

/// <summary>
/// Acquires reader lock associated with the given object.
Expand All @@ -100,9 +116,23 @@ private static AsyncLock GetExclusiveLock<T>(this T obj)
/// <param name="obj">The object to be locked.</param>
/// <param name="token">The token that can be used to abort acquisition operation.</param>
/// <returns>The acquired lock holder.</returns>
public static ValueTask<AsyncLock.Holder> AcquireReadLockAsync<T>(this T obj, CancellationToken token)
/// <exception cref="OperationCanceledException">The operation has been canceled.</exception>
public static ValueTask<AsyncLock.Holder> AcquireReadLockAsync<T>(this T obj, CancellationToken token = default)
where T : class => AsyncLock.ReadLock(obj.GetReaderWriterLock()).AcquireAsync(token);

/// <summary>
/// Acquires reader lock associated with the given object.
/// </summary>
/// <typeparam name="T">The type of the object to be locked.</typeparam>
/// <param name="obj">The object to be locked.</param>
/// <param name="timeout">The interval to wait for the lock.</param>
/// <param name="token">The token that can be used to abort acquisition operation.</param>
/// <returns>The acquired lock holder.</returns>
/// <exception cref="TimeoutException">The lock cannot be acquired during the specified amount of time.</exception>
/// <exception cref="OperationCanceledException">The operation has been canceled.</exception>
public static ValueTask<AsyncLock.Holder> AcquireReadLockAsync<T>(this T obj, TimeSpan timeout, CancellationToken token = default)
where T : class => AsyncLock.ReadLock(obj.GetReaderWriterLock()).AcquireAsync(timeout, token);

/// <summary>
/// Acquires writer lock associated with the given object.
/// </summary>
Expand All @@ -111,8 +141,9 @@ private static AsyncLock GetExclusiveLock<T>(this T obj)
/// <param name="timeout">The interval to wait for the lock.</param>
/// <returns>The acquired lock holder.</returns>
/// <exception cref="TimeoutException">The lock cannot be acquired during the specified amount of time.</exception>
public static ValueTask<AsyncLock.Holder> AcquireWriteLockAsync<T>(this T obj, TimeSpan timeout)
where T : class => AsyncLock.WriteLock(obj.GetReaderWriterLock()).AcquireAsync(timeout);
[Obsolete("Use AcquireWriteLockAsync(T, TimeSpan, CancellationToken) overload instead.", error: true)]
public static ValueTask<AsyncLock.Holder> AcquireWriteLockAsync<T>(T obj, TimeSpan timeout)
where T : class => AcquireWriteLockAsync(obj, timeout, CancellationToken.None);

/// <summary>
/// Acquires reader lock associated with the given object.
Expand All @@ -121,6 +152,19 @@ private static AsyncLock GetExclusiveLock<T>(this T obj)
/// <param name="obj">The object to be locked.</param>
/// <param name="token">The token that can be used to abort acquisition operation.</param>
/// <returns>The acquired lock holder.</returns>
public static ValueTask<AsyncLock.Holder> AcquireWriteLockAsync<T>(this T obj, CancellationToken token)
/// <exception cref="OperationCanceledException">The operation has been canceled.</exception>
public static ValueTask<AsyncLock.Holder> AcquireWriteLockAsync<T>(this T obj, CancellationToken token = default)
where T : class => AsyncLock.WriteLock(obj.GetReaderWriterLock()).AcquireAsync(token);

/// <summary>
/// Acquires reader lock associated with the given object.
/// </summary>
/// <typeparam name="T">The type of the object to be locked.</typeparam>
/// <param name="obj">The object to be locked.</param>
/// <param name="timeout">The interval to wait for the lock.</param>
/// <param name="token">The token that can be used to abort acquisition operation.</param>
/// <returns>The acquired lock holder.</returns>
/// <exception cref="OperationCanceledException">The operation has been canceled.</exception>
public static ValueTask<AsyncLock.Holder> AcquireWriteLockAsync<T>(this T obj, TimeSpan timeout, CancellationToken token = default)
where T : class => AsyncLock.WriteLock(obj.GetReaderWriterLock()).AcquireAsync(timeout, token);
}

0 comments on commit f63a24c

Please sign in to comment.