示例#1
0
        internal static void Release(ref AsyncSemaphoreSlimWrapper asyncSemaphoreSlimWrapper)
        {
            asyncSemaphoreSlimWrapper.DecreaseRef();

            if (asyncSemaphoreSlimWrapper.RefCount <= 0)
            {
                Lockers.TryRemove(asyncSemaphoreSlimWrapper.Key, out var removed);
            }
        }
示例#2
0
        internal static AsyncSemaphoreSlimWrapper GetOrCreate(string key)
        {
            AsyncSemaphoreSlimWrapper asyncSemaphoreSlimWrapper;

            if (Lockers.TryGetValue(key, out asyncSemaphoreSlimWrapper))
            {
                asyncSemaphoreSlimWrapper.IncreaseRef();
            }

            else
            {
                asyncSemaphoreSlimWrapper = new AsyncSemaphoreSlimWrapper(key, new SemaphoreSlim(1, 1));
                Lockers.TryAdd(key, asyncSemaphoreSlimWrapper);
            }

            return(asyncSemaphoreSlimWrapper);
        }