public void ThreadFinished(IIterationId id, ISchedule scheduler)
 {
     if (scheduler.Action == ScheduleAction.Idle)
     {
         Interlocked.Decrement(ref _localIdlerCount);
     }
 }
Beispiel #2
0
        public void Next(IIterationId id, ISchedule target)
        {
            ScheduleTable table = GetScheduleTable(target);

            ISchedule schedule = null;

            do
            {
                schedule = table.Schedules[table.ReadPosition];
                _strategies[table.ReadPosition].Next(id, schedule);

                if (schedule.Action == ScheduleAction.Idle)
                {
                    break;
                }

                table.ReadPosition++;
            } while (table.ReadPosition < _strategies.Length);

            if (table.ReadPosition == _strategies.Length && schedule.Action == ScheduleAction.Execute)
            {
                table.ReadPosition = 0;
                target.Action      = ScheduleAction.Execute;
                target.At          = MaxTarget(table.Schedules);
            }
            else
            {
                target.Action = ScheduleAction.Idle;
                target.At     = schedule.At;
            }
        }
        public void Next(IIterationId id, ISchedule scheduler)
        {
            bool thisThreadWasWorking = scheduler.Action == ScheduleAction.Execute;

            if (thisThreadWasWorking)
            {
                scheduler.Idle();
                Interlocked.Increment(ref _localIdlerCount);
            }
            else
            {
                int tryLockIdlerCount       = Interlocked.Decrement(ref _localIdlerCount);
                int estimatedworkingThreads = _pool.InitializedThreadCount - tryLockIdlerCount;

                if (estimatedworkingThreads <= ThreadLimit)
                {
                    scheduler.Execute();
                }
                else
                {
                    Interlocked.Increment(ref _localIdlerCount);
                    scheduler.Idle(DelayInterval);
                }
            }
        }
Beispiel #4
0
        public void ThreadFinished(IIterationId id, ISchedule scheduler)
        {
            ScheduleTable table = GetScheduleTable(scheduler);

            for (int i = 0; i < _strategies.Length; i++)
            {
                _strategies[i].ThreadFinished(id, table.Schedules[i]);
            }
        }
Beispiel #5
0
 public void Next(IIterationId id, ISchedule scheduler)
 {
     if (_executedBatchIterations < _batchSize)
     {
         Interlocked.Add(ref _executedBatchIterations, 1);
         scheduler.Execute();
     }
     else
     {
         scheduler.Idle(_pollInterval);
     }
 }
Beispiel #6
0
        public void Next(IIterationId id, ISchedule schedule)
        {
            long timerTicks = _timer.Value.Ticks;
            long delta      = timerTicks + ScheduleAheadTicks - _next;

            if (delta >= 0)
            {
                long current = Interlocked.Add(ref _next, _delayTicks);
                schedule.ExecuteAt(TimeSpan.FromTicks(current));
            }
            else
            {
                schedule.Idle(TimeSpan.FromTicks(Math.Abs(delta) + TimeSpan.TicksPerMillisecond));
            }
        }
 public void Next(IIterationId id, ISchedule scheduler)
 {
     if (_batchState == BatchState.Executing)
     {
         int next = Interlocked.Increment(ref _executedInBatch);
         if (next <= _batchSize)
         {
             scheduler.ExecuteAt(_executeAt);
         }
         else
         {
             scheduler.Idle(WaitDelay);
         }
     }
     else
     {
         scheduler.Idle(WaitDelay);
     }
 }
Beispiel #8
0
        public Scheduler(ISpeedStrategy strategy, IThreadPoolCounter counter, ITimer timer, IIterationId id)
        {
            if (strategy == null)
            {
                throw new ArgumentNullException(nameof(strategy));
            }
            if (counter == null)
            {
                throw new ArgumentNullException(nameof(counter));
            }

            _strategy = strategy;
            _counter  = counter;
            _id       = id ?? throw new ArgumentNullException(nameof(id));

            Timer = timer;

            _waiter = new SemiWait(Timer);
        }
 public void ThreadFinished(IIterationId id, ISchedule scheduler)
 {
 }
Beispiel #10
0
 public void ThreadStarted(IIterationId id, ISchedule scheduler)
 {
 }
Beispiel #11
0
 public IScheduler Create(IIterationId iterationContext)
 {
     return(_scheduler);
 }
Beispiel #12
0
 public void Next(IIterationId id, ISchedule scheduler)
 {
 }
Beispiel #13
0
        public IScheduler Create(IIterationId iterationContext)
        {
            IScheduler scheduler = new Scheduler.Scheduler(_speedStrategy, _counter, _timer, iterationContext);

            return(scheduler);
        }