Semaphore.cpp 493 B

1234567891011121314151617181920212223
  1. #include "all-headers.h"
  2. Semaphore::Semaphore (const uint32_t inInitialValue) :
  3. mWaitingTaskList(), mValue (inInitialValue) {}
  4. void Semaphore::sys_P (KERNEL_MODE) {
  5. if (mValue == 0) {
  6. kernel_blockRunningTaskInList(MODE_ mWaitingTaskList);
  7. }
  8. else {
  9. mValue --;
  10. }
  11. }
  12. void Semaphore::sys_V (IRQ_MODE) {
  13. TaskControlBlock * taskToRelease( mWaitingTaskList.removeFirstTask(MODE) );
  14. if (taskToRelease == nullptr) {
  15. mValue ++;
  16. }
  17. else {
  18. kernel_makeTaskReady(MODE_ taskToRelease);
  19. }
  20. }