![]() |
NetBurner 3.3.9
PDF Version |
An OS_CRIT object is used to establish critical sections of code that can only be run by one task at a time. Tasks that try to claim a critical section which is currently claimed by another task will stop and wait for that task to leave the critical section before continuing execution. More...
#include <nbrtos.h>
Inherits OS_TASK_DLY_OBJ.
Public Member Functions | |
OS_CRIT () | |
Create and initialize an OS_CRIT object. | |
uint8_t | Init () |
Initialize an OS_CRIT object to its default state. More... | |
uint8_t | LockAndEnter (uint32_t timeoutTicks=WAIT_FOREVER) |
Locks the current task to prevent task switching, and claims a critical section. More... | |
uint8_t | Enter (uint32_t timeoutTicks=WAIT_FOREVER) |
This function tries to enter or claim the critical section. More... | |
uint8_t | EnterNoWait () |
This function tries to enter or claim the critical section. However, this function does not wait if it is unable to enter or claim the critical section. More... | |
uint8_t | Leave () |
This function releases the critical section. More... | |
uint8_t | LeaveAndUnlock () |
This function unlocks the task and releases the critical section. More... | |
Friends | |
void | ForceReboot (bool fromIRQ) |
Forces the system hardware to perform a soft reset. | |
An OS_CRIT object is used to establish critical sections of code that can only be run by one task at a time. Tasks that try to claim a critical section which is currently claimed by another task will stop and wait for that task to leave the critical section before continuing execution.
uint8_t OS_CRIT::Enter | ( | uint32_t | timeoutTicks = WAIT_FOREVER | ) |
This function tries to enter or claim the critical section.
Important: You must call Leave() once for each successful Enter() call to release the critical section so that another task can run it.
timeoutTicks | How many time ticks do we want to wait for this critical section? Note: A timeout of 0 (zero) waits forever. |
OS_NO_ERR | - If we were successful in claiming the critical section or if our task owns it |
OS_TIMEOUT | - If we were unable to claim the section |
uint8_t OS_CRIT::EnterNoWait | ( | ) |
This function tries to enter or claim the critical section. However, this function does not wait if it is unable to enter or claim the critical section.
Important: You must call Leave() once for each successful Enter() call to release the critical section so that another task can run it.
OS_NO_ERR | - If we were successful in claiming the critical section or if our task owns it |
OS_TIMEOUT | - If we were unable to claim the section |
uint8_t OS_CRIT::Init | ( | ) |
Initialize an OS_CRIT object to its default state.
OS_NO_ERR | - If successful |
uint8_t OS_CRIT::Leave | ( | ) |
This function releases the critical section.
Important: This function must be called once for each successful Enter() or EnterNoWait() call to release the critical section so another task can run it.
OS_NO_ERR | - If we were successful in releasing the critical section |
OS_CRIT_ERR | - If we are trying to release a critical section that we do not own |
uint8_t OS_CRIT::LeaveAndUnlock | ( | ) |
This function unlocks the task and releases the critical section.
Important: This function must be called once for each successful LockAndEnter() call to both unlock and release the critical section so another task can run it.
OS_NO_ERR | - If we were successful in releasing the critical section |
uint8_t OS_CRIT::LockAndEnter | ( | uint32_t | timeoutTicks = WAIT_FOREVER | ) |
Locks the current task to prevent task switching, and claims a critical section.
Important:If it is unable to claim the critical section and times out, then the lock will be released. Otherwise LeaveAndUnlock() must be called once for each successful LockAndEnter() call to both unlock and release the critical section so that another task might run it.
timeoutTicks | How many time ticks do we want to wait for this critical section? Note: A timeout of 0 (zero) waits forever. |
OS_NO_ERR | - If we were successful in claiming the critical section or if our task owns it |
OS_TIMEOUT | - If we were unable to claim the section |