Medical Imaging Interaction Toolkit  2016.11.0
Medical Imaging Interaction Toolkit
mitkWeightedRoundRobinSchedulingAlgorithm.cpp
Go to the documentation of this file.
1 /*===================================================================
2 
3 The Medical Imaging Interaction Toolkit (MITK)
4 
5 Copyright (c) German Cancer Research Center,
6 Division of Medical and Biological Informatics.
7 All rights reserved.
8 
9 This software is distributed WITHOUT ANY WARRANTY; without
10 even the implied warranty of MERCHANTABILITY or FITNESS FOR
11 A PARTICULAR PURPOSE.
12 
13 See LICENSE.txt or http://www.mitk.org for details.
14 
15 ===================================================================*/
16 
17 #include "mitkSchedulableProcess.h"
19 #include <algorithm>
20 
22 {
23  return lhs->GetElapsedTime() < rhs->GetElapsedTime();
24 }
25 
27 {
28 }
29 
31 {
32 }
33 
35 {
36  const double threshold = 1.5;
37  size_t numProcesses = processQueue.size();
38 
39  if (numProcesses == 0)
40  return nullptr;
41 
42  boost::chrono::nanoseconds maxElapsedTime = (*std::max_element(processQueue.begin(), processQueue.end(), CompareElapsedTime))->GetElapsedTime();
43  mitk::SchedulableProcess* process = processQueue[0];
44 
45  if (numProcesses > 1)
46  {
47  boost::chrono::nanoseconds totalElapsedTime = process->GetTotalElapsedTime();
48  boost::chrono::nanoseconds elapsedTime = process->GetElapsedTime();
49 
50  if (totalElapsedTime >= maxElapsedTime || totalElapsedTime + elapsedTime >= maxElapsedTime * threshold)
51  {
52  process->ResetTotalElapsedTime();
53 
54  processQueue.erase(processQueue.begin());
55  processQueue.push_back(process);
56  }
57  }
58 
59  return process;
60 }
boost::chrono::nanoseconds GetElapsedTime() const
static bool CompareElapsedTime(mitk::SchedulableProcess *lhs, mitk::SchedulableProcess *rhs)
void ResetTotalElapsedTime(boost::chrono::nanoseconds carryover=boost::chrono::nanoseconds::zero())
SchedulableProcess * GetNextProcess(std::vector< SchedulableProcess * > &processQueue) override
boost::chrono::nanoseconds GetTotalElapsedTime() const