Exemple #1
0
        private void Release(LimitableResource Resource, long UsedAmount, long AvailableAmount)
        {
            int Index = GetIndex(Resource);

            lock (LockObj)
            {
                Current  [Index] -= UsedAmount;
                Available[Index] -= AvailableAmount;

                if (WaitingThreadsCount > 0)
                {
                    KConditionVariable.NotifyAll(System, WaitingThreads);
                }
            }
        }
Exemple #2
0
        private void Release(LimitableResource resource, long usedAmount, long availableAmount)
        {
            int index = GetIndex(resource);

            lock (_lockObj)
            {
                _current  [index] -= usedAmount;
                _available[index] -= availableAmount;

                if (_waitingThreadsCount > 0)
                {
                    KConditionVariable.NotifyAll(_system, _waitingThreads);
                }
            }
        }
Exemple #3
0
        public bool Reserve(LimitableResource Resource, long Amount, long Timeout)
        {
            long EndTimePoint = KTimeManager.ConvertNanosecondsToMilliseconds(Timeout);

            EndTimePoint += PerformanceCounter.ElapsedMilliseconds;

            bool Success = false;

            int Index = GetIndex(Resource);

            lock (LockObj)
            {
                long NewCurrent = Current[Index] + Amount;

                while (NewCurrent > Limit[Index] && Available[Index] + Amount <= Limit[Index])
                {
                    WaitingThreadsCount++;

                    KConditionVariable.Wait(System, WaitingThreads, LockObj, Timeout);

                    WaitingThreadsCount--;

                    NewCurrent = Current[Index] + Amount;

                    if (Timeout >= 0 && PerformanceCounter.ElapsedMilliseconds > EndTimePoint)
                    {
                        break;
                    }
                }

                if (NewCurrent <= Limit[Index])
                {
                    Current[Index] = NewCurrent;

                    Success = true;
                }
            }

            return(Success);
        }
Exemple #4
0
        public bool Reserve(LimitableResource resource, long amount, long timeout)
        {
            long endTimePoint = KTimeManager.ConvertNanosecondsToMilliseconds(timeout);

            endTimePoint += PerformanceCounter.ElapsedMilliseconds;

            bool success = false;

            int index = GetIndex(resource);

            lock (_lockObj)
            {
                long newCurrent = _current[index] + amount;

                while (newCurrent > _limit[index] && _available[index] + amount <= _limit[index])
                {
                    _waitingThreadsCount++;

                    KConditionVariable.Wait(_system, _waitingThreads, _lockObj, timeout);

                    _waitingThreadsCount--;

                    newCurrent = _current[index] + amount;

                    if (timeout >= 0 && PerformanceCounter.ElapsedMilliseconds > endTimePoint)
                    {
                        break;
                    }
                }

                if (newCurrent <= _limit[index])
                {
                    _current[index] = newCurrent;

                    success = true;
                }
            }

            return(success);
        }