Advertisement
Marko35S

Untitled

Jun 13th, 2018
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.02 KB | None | 0 0
  1. /*
  2.  * KEvent.cpp
  3.  *
  4.  *  Created on: Jun 3, 2018
  5.  *      Author: OS1
  6.  */
  7. #include "KEvent.h"
  8. #include "PCB.h"
  9. #include "Thread.h"
  10. #include "SCHEDULE.h"
  11. #include "IVTable.h"
  12. #include "Def.h"
  13. #include "IVTEntry.h"
  14.  
  15. KernelEvent::KernelEvent(IVTNo ivtNo){
  16.  
  17.     //lock
  18.  
  19.     myPCB = PCB::running;
  20.     IVTable::myInterruptVectorTable->entries[(int) ivtNo]->setEvent(this);
  21.  
  22.     //unlock
  23.  
  24.  
  25. }
  26.  
  27. KernelEvent::~KernelEvent(){
  28.  
  29.     IVTable::myInterruptVectorTable->entries[(int) ivtNo]->restoreOldRoutine();
  30.     IVTable::myInterruptVectorTable->entries[(int) ivtNo] = NULL;
  31.  
  32. }
  33.  
  34.  
  35. void KernelEvent::wait(){
  36.  
  37.     //lock
  38.  
  39.     if(myPCB == PCB::running && val-- == 0){
  40.         block();
  41.     }
  42.  
  43.     //unlock
  44.  
  45. }
  46.  
  47. void KernelEvent::signal(){
  48.  
  49.     //lock
  50.  
  51.  
  52.     if(val<1 && val++<0){
  53.         deblock();
  54.     }
  55.  
  56.     //unlock
  57. }
  58.  
  59. void KernelEvent::block() {
  60.  
  61.     //lock
  62.  
  63.         if(myPCB != NULL){
  64.             myPCB->state = BLOCKED;
  65.         }
  66.         dispatch();
  67.  
  68.     //unlock
  69. }
  70.  
  71. void KernelEvent::deblock() {
  72.  
  73.     //lock
  74.         myPCB->state = READY;
  75.         Scheduler::put(myPCB);
  76.     //unlock
  77. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement