diff options
author | vnugent <public@vaughnnugent.com> | 2024-03-31 17:00:45 -0400 |
---|---|---|
committer | vnugent <public@vaughnnugent.com> | 2024-03-31 17:00:45 -0400 |
commit | 21130c889bd8564b201aa16c8f645abdf85d374a (patch) | |
tree | 57e685f0f7e5c341264eb890112de35206f3d289 /lib/Utils/src/Async | |
parent | 55859158fbd0bf54473a0baeb486045a025c7c5d (diff) |
Squashed commit of the following:
commit 448a93bb1d18d032087afe2476ffccb98634a54c
Author: vnugent <public@vaughnnugent.com>
Date: Sun Mar 31 16:56:51 2024 -0400
ci: fix third-party dir cleanup
commit 9afed1427472da1ea13079f98dbe27339e55ee7d
Author: vnugent <public@vaughnnugent.com>
Date: Sun Mar 31 16:43:15 2024 -0400
perf: Deprecate unsafememoryhandle span extensions
commit 3ff90da4f02af47ea6d233fdd4445337ebe36452
Author: vnugent <public@vaughnnugent.com>
Date: Sat Mar 30 21:36:18 2024 -0400
refactor: Updates, advanced tracing, http optimizations
commit 8d6b79b5ae309b36f265ba81529bcef8bfcd7414
Merge: 6c1667b 5585915
Author: vnugent <public@vaughnnugent.com>
Date: Sun Mar 24 21:01:31 2024 -0400
Merge branch 'main' into develop
commit 6c1667be23597513537f8190e2f55d65eb9b7c7a
Author: vnugent <public@vaughnnugent.com>
Date: Fri Mar 22 12:01:53 2024 -0400
refactor: Overhauled native library loading and lazy init
commit ebf688f2f974295beabf7b5def7e6f6f150551d0
Author: vnugent <public@vaughnnugent.com>
Date: Wed Mar 20 22:16:17 2024 -0400
refactor: Update compression header files and macros + Ci build
commit 9c7b564911080ccd5cbbb9851a0757b05e1e9047
Author: vnugent <public@vaughnnugent.com>
Date: Tue Mar 19 21:54:49 2024 -0400
refactor: JWK overhaul & add length getter to FileUpload
commit 6d8c3444e09561e5957491b3cc1ae858e0abdd14
Author: vnugent <public@vaughnnugent.com>
Date: Mon Mar 18 16:13:20 2024 -0400
feat: Add FNV1a software checksum and basic correction tests
commit 00d182088cecefc08ca80b1faee9bed3f215f40b
Author: vnugent <public@vaughnnugent.com>
Date: Fri Mar 15 01:05:27 2024 -0400
chore: #6 Use utils filewatcher instead of built-in
commit d513c10d9895c6693519ef1d459c6a5a76929436
Author: vnugent <public@vaughnnugent.com>
Date: Sun Mar 10 21:58:14 2024 -0400
source tree project location updated
Diffstat (limited to 'lib/Utils/src/Async')
-rw-r--r-- | lib/Utils/src/Async/AsyncAccessSerializer.cs | 43 | ||||
-rw-r--r-- | lib/Utils/src/Async/AsyncQueue.cs | 12 |
2 files changed, 20 insertions, 35 deletions
diff --git a/lib/Utils/src/Async/AsyncAccessSerializer.cs b/lib/Utils/src/Async/AsyncAccessSerializer.cs index 76532bc..1beb4dc 100644 --- a/lib/Utils/src/Async/AsyncAccessSerializer.cs +++ b/lib/Utils/src/Async/AsyncAccessSerializer.cs @@ -1,5 +1,5 @@ /* -* Copyright (c) 2023 Vaughn Nugent +* Copyright (c) 2024 Vaughn Nugent * * Library: VNLib * Package: VNLib.Utils @@ -37,42 +37,35 @@ namespace VNLib.Utils.Async /// Creates a base concrete implementation of an <see cref="IAsyncAccessSerializer{TMoniker}"/> /// </summary> /// <typeparam name="TMoniker">The moniker (key) type</typeparam> - public class AsyncAccessSerializer<TMoniker> : IAsyncAccessSerializer<TMoniker>, ICacheHolder where TMoniker : notnull + /// <remarks> + /// Initializes a new <see cref="AsyncAccessSerializer{TMoniker}"/> with the desired + /// caching pool size and initial capacity + /// </remarks> + /// <param name="maxPoolSize">The maxium number of cached wait entry objects</param> + /// <param name="initialCapacity">The initial capacity of the wait table</param> + /// <param name="keyComparer">The moniker key comparer</param> + public class AsyncAccessSerializer<TMoniker>(int maxPoolSize, int initialCapacity, IEqualityComparer<TMoniker>? keyComparer) + : IAsyncAccessSerializer<TMoniker>, ICacheHolder where TMoniker : notnull { /// <summary> /// The mutual exclusion monitor locking object /// </summary> - protected object StoreLock { get; } + protected object StoreLock { get; } = new(); /// <summary> /// A cache pool for <see cref="WaitEntry"/> /// </summary> - protected Stack<WaitEntry> EntryPool { get; } + protected Stack<WaitEntry> EntryPool { get; } = new(maxPoolSize); /// <summary> /// The table containing all active waiters /// </summary> - protected Dictionary<TMoniker, WaitEntry> WaitTable { get; } + protected Dictionary<TMoniker, WaitEntry> WaitTable { get; } = new(initialCapacity, keyComparer); /// <summary> /// The maxium number of elements allowed in the internal entry cache pool /// </summary> - protected int MaxPoolSize { get; } - - /// <summary> - /// Initializes a new <see cref="AsyncAccessSerializer{TMoniker}"/> with the desired - /// caching pool size and initial capacity - /// </summary> - /// <param name="maxPoolSize">The maxium number of cached wait entry objects</param> - /// <param name="initialCapacity">The initial capacity of the wait table</param> - /// <param name="keyComparer">The moniker key comparer</param> - public AsyncAccessSerializer(int maxPoolSize, int initialCapacity, IEqualityComparer<TMoniker>? keyComparer) - { - MaxPoolSize = maxPoolSize; - StoreLock = new(); - EntryPool = new(maxPoolSize); - WaitTable = new(initialCapacity, keyComparer); - } + protected int MaxPoolSize { get; } = maxPoolSize; ///<inheritdoc/> public virtual Task WaitAsync(TMoniker moniker, CancellationToken cancellation = default) @@ -464,11 +457,9 @@ namespace VNLib.Utils.Async * next task in the queue and be awaitable as a task */ - private sealed class TaskNode : Task + private sealed class TaskNode(Action<object?> callback, object item, CancellationToken cancellation) + : Task(callback, item, cancellation) { - public TaskNode(Action<object?> callback, object item, CancellationToken cancellation) : base(callback, item, cancellation) - { } - public TaskNode? Next { get; set; } } @@ -500,7 +491,7 @@ namespace VNLib.Utils.Async /// another waiter is not selected. /// </para> /// </summary> - /// <returns>A value that indicates if the task was transition successfully</returns> + /// <returns>A value that indicates if the task was transitioned successfully</returns> public readonly bool Release() { //return success if no next waiter diff --git a/lib/Utils/src/Async/AsyncQueue.cs b/lib/Utils/src/Async/AsyncQueue.cs index 45f1219..e94d08e 100644 --- a/lib/Utils/src/Async/AsyncQueue.cs +++ b/lib/Utils/src/Async/AsyncQueue.cs @@ -1,5 +1,5 @@ /* -* Copyright (c) 2023 Vaughn Nugent +* Copyright (c) 2024 Vaughn Nugent * * Library: VNLib * Package: VNLib.Utils @@ -93,19 +93,13 @@ namespace VNLib.Utils.Async /// Initalizes a new unbound channel based queue /// </summary> /// <param name="ubOptions">Channel options</param> - public AsyncQueue(UnboundedChannelOptions ubOptions) - { - _channel = Channel.CreateUnbounded<T>(ubOptions); - } + public AsyncQueue(UnboundedChannelOptions ubOptions) => _channel = Channel.CreateUnbounded<T>(ubOptions); /// <summary> /// Initalizes a new bound channel based queue /// </summary> /// <param name="options">Channel options</param> - public AsyncQueue(BoundedChannelOptions options) - { - _channel = Channel.CreateBounded<T>(options); - } + public AsyncQueue(BoundedChannelOptions options) => _channel = Channel.CreateBounded<T>(options); /// <inheritdoc/> public bool TryEnque(T item) => _channel.Writer.TryWrite(item); |