1234567891011121314151617181920212223 |
- #include "all-headers.h"
- Semaphore::Semaphore (const uint32_t inInitialValue) :
- mWaitingTaskList(), mValue (inInitialValue) {}
- void Semaphore::sys_P (KERNEL_MODE) {
- if (mValue == 0) {
- kernel_blockRunningTaskInList(MODE_ mWaitingTaskList);
- }
- else {
- mValue --;
- }
- }
- void Semaphore::sys_V (IRQ_MODE) {
- TaskControlBlock * taskToRelease( mWaitingTaskList.removeFirstTask(MODE) );
- if (taskToRelease == nullptr) {
- mValue ++;
- }
- else {
- kernel_makeTaskReady(MODE_ taskToRelease);
- }
- }
|