Exemple #1
0
        public UniqueLockSemaphore(ref UniqueLockSemaphore other)
        {
            _semaphore = other._semaphore;
            _isLocked  = other._isLocked;

            other._isLocked  = false;
            other._semaphore = null;
        }
Exemple #2
0
        public void Dispose()
        {
            if (_isLocked)
            {
                _semaphore.Unlock();

                _isLocked  = false;
                _semaphore = null;
            }
        }
Exemple #3
0
        public static Result MakeUniqueLockWithPin <T>(out IUniqueLock uniqueLock, SemaphoreAdaptor semaphore,
                                                       ref ReferenceCountedDisposable <T> objectToPin) where T : class, IDisposable
        {
            UnsafeHelpers.SkipParamInit(out uniqueLock);

            UniqueLockSemaphore tempUniqueLock = default;

            try
            {
                Result rc = TryAcquireCountSemaphore(out tempUniqueLock, semaphore);
                if (rc.IsFailure())
                {
                    return(rc);
                }

                uniqueLock = new UniqueLockWithPin <T>(ref tempUniqueLock, ref objectToPin);
                return(Result.Success);
            }
            finally
            {
                tempUniqueLock.Dispose();
            }
        }
Exemple #4
0
 public UniqueLockSemaphore(SemaphoreAdaptor semaphore)
 {
     _semaphore = semaphore;
     _isLocked  = false;
 }
Exemple #5
0
        public static Result TryAcquireCountSemaphore(out UniqueLockSemaphore uniqueLock, SemaphoreAdaptor semaphore)
        {
            UniqueLockSemaphore tempUniqueLock = default;

            try
            {
                tempUniqueLock = new UniqueLockSemaphore(semaphore);

                if (!tempUniqueLock.TryLock())
                {
                    UnsafeHelpers.SkipParamInit(out uniqueLock);
                    return(ResultFs.OpenCountLimit.Log());
                }

                uniqueLock = new UniqueLockSemaphore(ref tempUniqueLock);
                return(Result.Success);
            }
            finally
            {
                tempUniqueLock.Dispose();
            }
        }