Medical Imaging Interaction Toolkit  2016.11.0
Medical Imaging Interaction Toolkit
mitkScheduler.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 
18 #include "mitkSchedulableProcess.h"
19 #include "mitkScheduler.h"
21 #include <algorithm>
22 #include <cassert>
23 #include <vector>
24 
25 struct mitk::Scheduler::Impl
26 {
27  std::vector<SchedulableProcess*> processQueue;
28  SchedulingAlgorithmBase* algorithm;
29 };
30 
32  : m_Impl(new Impl)
33 {
34  switch (algorithm)
35  {
37  m_Impl->algorithm = new mitk::RoundRobinSchedulingAlgorithm;
38  break;
39 
41  m_Impl->algorithm = new mitk::WeightedRoundRobinSchedulingAlgorithm;
42  break;
43 
44  default:
45  assert(false && "Unknown scheduling algorithm!");
46  }
47 }
48 
50 {
51  delete m_Impl->algorithm;
52  delete m_Impl;
53 }
54 
56 {
57  if (process == nullptr)
58  return;
59 
60  if (std::find(m_Impl->processQueue.begin(), m_Impl->processQueue.end(), process) == m_Impl->processQueue.end())
61  m_Impl->processQueue.push_back(process);
62 }
63 
65 {
66  if (process == nullptr)
67  return;
68 
69  auto it = std::find(m_Impl->processQueue.begin(), m_Impl->processQueue.end(), process);
70 
71  if (it != m_Impl->processQueue.end())
72  m_Impl->processQueue.erase(it);
73 }
74 
76 {
77  return m_Impl->processQueue.empty();
78 }
79 
81 {
82  return !m_Impl->processQueue.empty()
83  ? m_Impl->processQueue[0]
84  : nullptr;
85 }
86 
88 {
89  return m_Impl->algorithm->GetNextProcess(m_Impl->processQueue);
90 }
SchedulableProcess * GetCurrentProcess()
void AddProcess(SchedulableProcess *process)
void RemoveProcess(SchedulableProcess *process)
SchedulableProcess * GetNextProcess()
Scheduler(SchedulingAlgorithm::Enum algorithm=SchedulingAlgorithm::RoundRobin)
bool IsEmpty() const