Ejemplo n.º 1
0
        public UniqueLockWithPin(ref UniqueLockSemaphore semaphore, ref ReferenceCountedDisposable <T> pinnedObject)
        {
            Shared.Move(out _semaphore, ref semaphore);
            Shared.Move(out _pinnedObject, ref pinnedObject);

            Assert.True(_semaphore.IsLocked);
        }
Ejemplo n.º 2
0
        public UniqueLockSemaphore(ref UniqueLockSemaphore other)
        {
            _semaphore = other._semaphore;
            _isLocked  = other._isLocked;

            other._isLocked  = false;
            other._semaphore = null;
        }
Ejemplo n.º 3
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();
            }
        }
Ejemplo n.º 4
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();
            }
        }