OOStuBS - Technische Informatik II (TI-II)  2.4
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 
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 
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 
52  log << "Task4 created" << endl;
53 }
54 
56  log << "Finished Setup of Task4" << endl;
57 }
58 
60  kout.clear();
61  kout.setpos(31,1);
62  kout << "OOStuBs - Task 4" << endl << endl;
63  log << "Inserting RotatingCursor in Scheduler" << endl;
65  log << "Inserting Counter 1 in Scheduler" << endl;
67  log << "Inserting Counter 2 in Scheduler" << endl;
69 }
70 
72  log << "Switching sub tasks to cooperative scheduling" << endl;
76 }