Beispiel #1
0
        public void Dispose()
        {
            if (_pinnedObject != null)
            {
                _semaphore.Dispose();
                _pinnedObject.Dispose();

                _pinnedObject = null;
            }
        }
Beispiel #2
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();
            }
        }
Beispiel #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();
            }
        }