add a scanner, but this seems to be a wrong solution. Change open-source head
This commit is contained in:
@@ -1,30 +1,10 @@
|
||||
//-----------------------------------------------------------------------
|
||||
// -----------------------------------------------------------------------
|
||||
// -----------------------------------------------------------------------------
|
||||
// file="SingleConsumerBell"
|
||||
// Project: StgSharp
|
||||
// AuthorGroup: Nitload
|
||||
// Copyright (c) Nitload. All rights reserved.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to deal
|
||||
// in the Software without restriction, including without limitation the rights
|
||||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
// copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in all
|
||||
// copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
// SOFTWARE.
|
||||
//
|
||||
// -----------------------------------------------------------------------
|
||||
// -----------------------------------------------------------------------
|
||||
// Copyright (c) Nitload.
|
||||
// SPDX-License-Identifier: MIT
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
using System;
|
||||
using System.Threading;
|
||||
|
||||
@@ -34,15 +14,15 @@ namespace StgSharp.Threading
|
||||
/// A single-consumer bell/signal primitive.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// <para> Producers can call <see cref="Set" /> multiple times to publish signals. The bell
|
||||
/// <para>Producers can call <see cref="Set" /> multiple times to publish signals. The bell
|
||||
/// keeps a pending count of not-yet-consumed signals. The consumer uses <see
|
||||
/// cref="Wait(object, CancellationToken)" /> or <see cref="TryWait(object)" /> to consume
|
||||
/// signals.</para> <para> When a producer increments the pending count from 0 to 1, the
|
||||
/// signals. </para> <para>When a producer increments the pending count from 0 to 1, the
|
||||
/// internal event is set to wake the consumer. Consuming via <see cref="TryWait(object)" />
|
||||
/// or <see cref="Wait(object, CancellationToken)" /> clears the entire pending count
|
||||
/// (aggregate consumption). If new signals arrive while resetting, the event is set again to
|
||||
/// avoid missed signals.</para> <para> Ownership: only the specified <c> owner </c> can call
|
||||
/// the consumer APIs.</para>
|
||||
/// avoid missed signals. </para> <para>Ownership: only the specified <c> owner </c> can call
|
||||
/// the consumer APIs. </para>
|
||||
/// </remarks>
|
||||
public sealed class SingleConsumerBell : IDisposable
|
||||
{
|
||||
@@ -65,7 +45,10 @@ namespace StgSharp.Threading
|
||||
/// <exception cref="ArgumentNullException">
|
||||
/// Thrown if <paramref name="owner" /> is null.
|
||||
/// </exception>
|
||||
public SingleConsumerBell(object owner, int spinCount = 100)
|
||||
public SingleConsumerBell(
|
||||
object owner,
|
||||
int spinCount = 100
|
||||
)
|
||||
{
|
||||
_owner = owner ?? throw new ArgumentNullException(nameof(owner));
|
||||
_evt = new ManualResetEventSlim(false, spinCount);
|
||||
@@ -113,13 +96,15 @@ namespace StgSharp.Threading
|
||||
/// The consumer object; must be the same reference provided at construction.
|
||||
/// </param>
|
||||
/// <returns>
|
||||
/// <c> true </c> if a signal was available (pending or event set); otherwise <c> false
|
||||
/// </c>.
|
||||
/// <c> true </c> if a signal was available (pending or event set); otherwise
|
||||
/// <c>false</c>.
|
||||
/// </returns>
|
||||
/// <exception cref="InvalidOperationException">
|
||||
/// Thrown if <paramref name="consumer" /> is not the owner.
|
||||
/// </exception>
|
||||
public bool TryWait(object consumer)
|
||||
public bool TryWait(
|
||||
object consumer
|
||||
)
|
||||
{
|
||||
if (!ReferenceEquals(_owner, consumer)) {
|
||||
throw new InvalidOperationException("This bell is owned by another consumer.");
|
||||
@@ -153,7 +138,10 @@ namespace StgSharp.Threading
|
||||
/// <exception cref="InvalidOperationException">
|
||||
/// Thrown if <paramref name="consumer" /> is not the owner.
|
||||
/// </exception>
|
||||
public void Wait(object consumer, CancellationToken cancellationToken = default)
|
||||
public void Wait(
|
||||
object consumer,
|
||||
CancellationToken cancellationToken = default
|
||||
)
|
||||
{
|
||||
if (!ReferenceEquals(_owner, consumer)) {
|
||||
throw new InvalidOperationException("This bell is owned by another consumer.");
|
||||
|
||||
Reference in New Issue
Block a user