summaryrefslogtreecommitdiffstats
path: root/Master/Real-Time Systems/Praktikum1/Aufgabe3/src/EDFScheduler.cpp
blob: 2f3a5c26f547ad07dfa1a315182c5611da5e8d34 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
/*
 * EDFScheduler.cpp
 *
 *  Created on: 07.11.2010
 *      Author: sven
 */

#include "EDFScheduler.h"
#include <iostream>
EDFScheduler::EDFScheduler() {
	// TODO Auto-generated constructor stub

}

EDFScheduler::~EDFScheduler() {
	// TODO Auto-generated destructor stub
}
void EDFScheduler::run(task_set& tasks,int ci)
{
	cout << "EDF" << endl;
	if(!test(tasks)) {
		cout << "Taskset not schedulable!" << endl;
		return;
	}
	for(unsigned int task_count = 0; task_count < tasks.size(); task_count++)
	{
		m_queue.push(&tasks[task_count]);
	}
	while (!m_queue.empty()) {
		Task* t = m_queue.top();
		t->dump();
		m_queue.pop();
	}
	for(int step= 0; step < ci; step++)
	{
		cout << (step + 1) << " ";
		edf_queue edfq;
		for(unsigned int task_count = 0; task_count < tasks.size(); task_count++)
		{
			edfq.push(&tasks[task_count]);
		}
		bool scheduledAtask = false;
		while (!edfq.empty()) {
			Task* t = edfq.top();
			if(!scheduledAtask && (t->getActC() > 0) ) {
				t->execute();
				scheduledAtask = true;
			} else {
				t->requeue();
			}
			edfq.pop();
		}
		if (!scheduledAtask) {
			cout << "no task needs to run";
		}
		cout << endl;
	}
}
bool EDFScheduler::test(task_set& taskset)
{
	bool res = false;
	unsigned int sum = 0;
	for(unsigned int i=0;i<taskset.size();i++)
	{
		Task &t = taskset[i];
		sum += static_cast<double>(t.getOrigC()) / static_cast<double>(t.getOrigP());
		if(t.getOrigC() > t.getOrigP()) {
			return false;
		}
	}
	if( sum <= 1.0) {
		res = true;
	}
	return res;
}