Esempio n. 1
0
        async ValueTask <WaitHandleDistributedSemaphoreHandle?> IInternalDistributedSemaphore <WaitHandleDistributedSemaphoreHandle> .InternalTryAcquireAsync(TimeoutValue timeout, CancellationToken cancellationToken)
        {
            var semaphore = await DistributedWaitHandleHelpers.CreateAndWaitAsync(
                createHandle : this.CreateSemaphore,
                abandonmentCheckCadence : this._abandonmentCheckCadence,
                timeout : timeout,
                cancellationToken : cancellationToken
                ).ConfigureAwait(false);

            return(semaphore != null ? new WaitHandleDistributedSemaphoreHandle(semaphore) : null);
        }
Esempio n. 2
0
        /// <summary>
        /// Constructs a lock with the given <paramref name="name"/>.
        ///
        /// <paramref name="abandonmentCheckCadence"/> specifies how frequently we refresh our <see cref="Semaphore"/> object in case it is abandoned by
        /// its original owner. The default is 2s.
        ///
        /// Unless <paramref name="exactName"/> is specified, <paramref name="name"/> will be escaped/hashed to ensure name validity.
        /// </summary>
        public WaitHandleDistributedSemaphore(string name, int maxCount, TimeSpan?abandonmentCheckCadence = null, bool exactName = false)
        {
            if (maxCount < 1)
            {
                throw new ArgumentOutOfRangeException(nameof(maxCount), maxCount, "must be positive");
            }

            this.Name     = DistributedWaitHandleHelpers.ValidateAndFinalizeName(name, exactName);
            this.MaxCount = maxCount;
            this._abandonmentCheckCadence = DistributedWaitHandleHelpers.ValidateAndFinalizeAbandonmentCheckCadence(abandonmentCheckCadence);
        }
Esempio n. 3
0
        async ValueTask <EventWaitHandleDistributedLockHandle?> IInternalDistributedLock <EventWaitHandleDistributedLockHandle> .InternalTryAcquireAsync(
            TimeoutValue timeout,
            CancellationToken cancellationToken)
        {
            var @event = await DistributedWaitHandleHelpers.CreateAndWaitAsync(
                createHandle : this.CreateEvent,
                abandonmentCheckCadence : this._abandonmentCheckCadence,
                timeout : timeout,
                cancellationToken : cancellationToken
                ).ConfigureAwait(false);

            return(@event != null ? new EventWaitHandleDistributedLockHandle(@event) : null);
        }
Esempio n. 4
0
 /// <summary>
 /// Constructs a lock with the given <paramref name="name"/>.
 ///
 /// <paramref name="abandonmentCheckCadence"/> specifies how frequently we refresh our <see cref="EventWaitHandle"/> object in case it is abandoned by
 /// its original owner. The default is 2s.
 ///
 /// Unless <paramref name="exactName"/> is specified, <paramref name="name"/> will be escaped/hashed to ensure name validity.
 /// </summary>
 public EventWaitHandleDistributedLock(string name, TimeSpan?abandonmentCheckCadence = null, bool exactName = false)
 {
     this.Name = DistributedWaitHandleHelpers.ValidateAndFinalizeName(name, exactName);
     this._abandonmentCheckCadence = DistributedWaitHandleHelpers.ValidateAndFinalizeAbandonmentCheckCadence(abandonmentCheckCadence);
 }