CMSIS-RTOS2  Version 2.0.0
Real-Time Operating System: API and RTX Reference Implementation
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
Thread Flags

Synchronize threads using flags. More...

Functions

int32_t osThreadFlagsSet (osThreadId_t thread_id, int32_t flags)
 Set the specified Thread Flags of a thread. More...
 
int32_t osThreadFlagsClear (int32_t flags)
 Clear the specified Thread Flags of current running thread. More...
 
int32_t osThreadFlagsGet (void)
 Get the current Thread Flags of current running thread. More...
 
int32_t osThreadFlagsWait (int32_t flags, uint32_t options, uint32_t timeout)
 Wait for one or more Thread Flags of the current running thread to become signaled. More...
 

Description

Thread Flags are a more specialized version of the Event Flags. See Event Flags. While Event Flags can be used to globally signal a number of threads, thread flags are only send to a single specific thread. Every thread instance can receive thread flags without any additional allocation of a thread flags object.

Function Documentation

int32_t osThreadFlagsSet ( osThreadId_t  thread_id,
int32_t  flags 
)
Parameters
[in]thread_idthread ID obtained by osThreadNew or osThreadGetId.
[in]flagsspecifies the flags of the thread that shall be set.
Returns
thread flags after setting or error code if negative.

Set the thread flags for a thread instance specified by thread_id. This function may be used also within interrupt service routines. The threads waiting for the flag set will be notified to resume from BLOCKED state.

Code Example

void Thread (void *arg);
static void EX_Signal_1 (void) {
int32_t signals;
osThreadId_t thread_id;
thread_id = osThreadNew (Thread, NULL, NULL);
signals = osThreadFlagsSet (event_id, 0x00000001ul); // Send signals to the created thread
}
osStatus osThreadFlagsClear ( int32_t  flags)
Parameters
[in]flagsspecifies the flags of the thread that shall be cleared.
Returns
thread flags before clearing or error code if negative.

Clear the specified event flags set for the a calling thread.

int32_t osThreadFlagsGet ( void  )
Returns
current thread flags.

Return the event flags currently set for the calling thread.

int32_t osThreadFlagsWait ( int32_t  flags,
uint32_t  options,
uint32_t  timeout 
)
Parameters
[in]flagsspecifies the flags to wait for.
[in]optionsspecifies flags options (osFlagsXxxx).
[in]timeoutTimeout Value or 0 in case of no time-out.
Returns
thread flags before clearing or error code if negative.

Suspend the execution of the current RUNNING thread until any or all specified thread flags with the parameter flags are set. The options parameter specifies the wait condition.

Option
osFlagsWaitAny Wait for any flag (default).
osFlagsWaitAll Wait for all flags.
osFlagsNoClear Do not clear flags which have been specified to wait for.

If osFlagsNoClear is set in the options osThreadFlagsClear can be used to clear flags manually.

When these thread flags are already set, the function returns instantly. Otherwise the thread is put into the state BLOCKED.

Code Example

#include "cmsis_os2.h"
void Thread (void* arg) {
;
osThreadFlagsWait (0x00000001ul, NULL, osWaitForever); //Wait forever until event 0x01 is set.
;
}