OOStuBS - Technische Informatik II (TI-II)
2.4
Hauptseite
Zusätzliche Informationen
Klassen
Dateien
Auflistung der Dateien
Datei-Elemente
src
user
task4.cc
gehe zur Dokumentation dieser Datei
1
#include "
user/task4.h
"
2
#include "
object/lock.h
"
3
#include "
object/kout.h
"
4
#include "
object/keyboard.h
"
5
#include "
object/scheduler.h
"
6
#include "
object/log.h
"
7
8
Task4::RotCursor::RotCursor
(
unsigned
short
x,
unsigned
short
y) : i(0), x(x), y(y), coop(false){}
9
10
void
Task4::RotCursor::action
(){
11
while
(
true
)
12
{
13
lock
.
lock
();
14
kout
.
flush
();
15
kout
.
setpos
(x, y);
16
switch
(i++%4)
17
{
18
case
(0):
kout
<<
'|'
;
19
break
;
20
case
(1):
kout
<<
'/'
;
21
break
;
22
case
(2):
kout
<<
'-'
;
23
break
;
24
case
(3):
kout
<<
'\\'
;
25
break
;
26
}
27
kout
.
flush
();
28
lock
.
unlock
();
29
if
(
coop
)
30
yield
();
31
}
32
}
33
34
Task4::Counter::Counter
(
unsigned
short
x,
unsigned
short
y) : i(0), x(x), y(y),
coop
(false){}
35
36
void
Task4::Counter::action
(){
37
while
(
true
)
38
{
39
lock
.
lock
();
40
kout
.
flush
();
41
kout
.
setpos
(x, y);
42
kout
<<
"Counter: "
<< i++ <<
endl
;
43
lock
.
unlock
();
44
if
(
coop
)
45
yield
();
46
}
47
}
48
49
Task4::Task4
() :
rotCursor
(
rotCursorX
,
rotCursorY
),
50
counter1
(
counter1X
,
counter1Y
),
51
counter2
(
counter2X
,
counter2Y
){
52
log
<<
"Task4 created"
<<
endl
;
53
}
54
55
Task4::~Task4
(){
56
log
<<
"Finished Setup of Task4"
<<
endl
;
57
}
58
59
void
Task4::action
(){
60
kout
.
clear
();
61
kout
.
setpos
(31,1);
62
kout
<<
"OOStuBs - Task 4"
<<
endl
<<
endl
;
63
log
<<
"Inserting RotatingCursor in Scheduler"
<<
endl
;
64
scheduler
.
insert
(
rotCursor
);
65
log
<<
"Inserting Counter 1 in Scheduler"
<<
endl
;
66
scheduler
.
insert
(
counter1
);
67
log
<<
"Inserting Counter 2 in Scheduler"
<<
endl
;
68
scheduler
.
insert
(
counter2
);
69
}
70
71
void
Task4::enableCoop
(){
72
log
<<
"Switching sub tasks to cooperative scheduling"
<<
endl
;
73
rotCursor
.
enableCoop
();
74
counter1
.
enableCoop
();
75
counter2
.
enableCoop
();
76
}
Erzeugt am Mon Jun 30 2014 07:13:28 für OOStuBS - Technische Informatik II (TI-II) von
1.8.1.2