Mbed OS Reference
Loading...
Searching...
No Matches
ThisThread namespace

Functions

uint32_t flags_clear (uint32_t flags)
 The ThisThread namespace allows controlling the current thread. More...
 
uint32_t flags_get ()
 Returns the Thread Flags currently set for the currently running thread. More...
 
uint32_t flags_wait_all (uint32_t flags, bool clear=true)
 Wait for all of the specified Thread Flags to become signaled for the current thread. More...
 
uint32_t flags_wait_any (uint32_t flags, bool clear=true)
 Wait for any of the specified Thread Flags to become signaled for the current thread. More...
 
uint32_t flags_wait_all_for (uint32_t flags, uint32_t millisec, bool clear=true)
 Wait for all of the specified Thread Flags to become signaled for the current thread. More...
 
uint32_t flags_wait_all_for (uint32_t flags, Kernel::Clock::duration_u32 rel_time, bool clear=true)
 Wait for all of the specified Thread Flags to become signaled for the current thread. More...
 
uint32_t flags_wait_all_until (uint32_t flags, uint64_t millisec, bool clear=true)
 Wait for all of the specified Thread Flags to become signaled for the current thread. More...
 
uint32_t flags_wait_all_until (uint32_t flags, Kernel::Clock::time_point abs_time, bool clear=true)
 Wait for all of the specified Thread Flags to become signaled for the current thread. More...
 
uint32_t flags_wait_any_for (uint32_t flags, uint32_t millisec, bool clear=true)
 Wait for any of the specified Thread Flags to become signaled for the current thread. More...
 
uint32_t flags_wait_any_for (uint32_t flags, Kernel::Clock::duration_u32 rel_time, bool clear=true)
 Wait for any of the specified Thread Flags to become signaled for the current thread. More...
 
uint32_t flags_wait_any_until (uint32_t flags, uint64_t millisec, bool clear=true)
 Wait for any of the specified Thread Flags to become signaled for the current thread. More...
 
uint32_t flags_wait_any_until (uint32_t flags, Kernel::Clock::time_point abs_time, bool clear=true)
 Wait for any of the specified Thread Flags to become signaled for the current thread. More...
 
void sleep_for (uint32_t millisec)
 Sleep for a specified time period in millisec: More...
 
void sleep_for (Kernel::Clock::duration_u32 rel_time)
 Sleep for a specified time period: More...
 
void sleep_until (uint64_t millisec)
 Sleep until a specified time in millisec The specified time is according to Kernel::get_ms_count(). More...
 
void sleep_until (Kernel::Clock::time_point abs_time)
 Sleep until a specified time in millisec The specified time is according to Kernel::Clock. More...
 
void yield ()
 Pass control to next equal-priority thread that is in state READY. More...
 
osThreadId_t get_id ()
 Get the thread id of the current running thread. More...
 
const char * get_name ()
 Get the thread name of the current running thread. More...
 

Detailed Description

Function Documentation

◆ flags_clear()

uint32_t flags_clear ( uint32_t  flags)

The ThisThread namespace allows controlling the current thread.

Example:

#include "mbed.h"
#include "rtos.h"
Thread thread;
DigitalOut led1(LED1);
#define STOP_FLAG 1
// Blink function toggles the led in a long running loop
void blink(DigitalOut *led) {
while (!ThisThread::flags_wait_any_for(STOP_FLAG, 1000)) {
*led = !*led;
}
}
// Spawns a thread to run blink for 5 seconds
int main() {
thread.start(callback(blink, &led1));
thread.signal_set(STOP_FLAG);
thread.join();
}
The Thread class allow defining, creating, and controlling thread functions in the system.
Definition: Thread.h:92
osStatus join()
Wait for thread to terminate.
osStatus start(mbed::Callback< void()> task)
Starts a thread executing the specified function.
uint32_t flags_wait_any_for(uint32_t flags, uint32_t millisec, bool clear=true)
Wait for any of the specified Thread Flags to become signaled for the current thread.
void sleep_for(uint32_t millisec)
Sleep for a specified time period in millisec:

Clears the specified Thread Flags of the currently running thread.

Parameters
flagsspecifies the flags of the thread that should be cleared.
Returns
thread flags before clearing.
Note
You cannot call this function from ISR context.
See also
Thread::flags_set

◆ flags_get()

uint32_t flags_get ( )

Returns the Thread Flags currently set for the currently running thread.

Returns
current thread flags or 0 if not in a valid thread.
Note
You cannot call this function from ISR context.
See also
Thread::flags_set

◆ flags_wait_all()

uint32_t flags_wait_all ( uint32_t  flags,
bool  clear = true 
)

Wait for all of the specified Thread Flags to become signaled for the current thread.

Parameters
flagsspecifies the flags to wait for
clearwhether to clear the specified flags after waiting for them. (default: true)
Returns
actual thread flags before clearing, which will satisfy the wait
Note
You cannot call this function from ISR context.
See also
Thread::flags_set

◆ flags_wait_any()

uint32_t flags_wait_any ( uint32_t  flags,
bool  clear = true 
)

Wait for any of the specified Thread Flags to become signaled for the current thread.

Parameters
flagsspecifies the flags to wait for
clearwhether to clear the specified flags after waiting for them. (default: true)
Returns
actual thread flags before clearing, which will satisfy the wait
Note
You cannot call this function from ISR context.
See also
Thread::flags_set

◆ flags_wait_all_for() [1/2]

uint32_t flags_wait_all_for ( uint32_t  flags,
uint32_t  millisec,
bool  clear = true 
)

Wait for all of the specified Thread Flags to become signaled for the current thread.

Parameters
flagsspecifies the flags to wait for
millisectimeout value.
clearwhether to clear the specified flags after waiting for them. (default: true)
Returns
actual thread flags before clearing, which may not satisfy the wait
Note
You cannot call this function from ISR context.
See also
Thread::flags_set
Deprecated:
Pass a chrono duration, not an integer millisecond count. For example use 5s rather than 5000.

◆ flags_wait_all_for() [2/2]

uint32_t flags_wait_all_for ( uint32_t  flags,
Kernel::Clock::duration_u32  rel_time,
bool  clear = true 
)

Wait for all of the specified Thread Flags to become signaled for the current thread.

Parameters
flagsspecifies the flags to wait for
rel_timetimeout value.
clearwhether to clear the specified flags after waiting for them. (default: true)
Returns
actual thread flags before clearing, which may not satisfy the wait
Note
You cannot call this function from ISR context.
See also
Thread::flags_set

◆ flags_wait_all_until() [1/2]

uint32_t flags_wait_all_until ( uint32_t  flags,
uint64_t  millisec,
bool  clear = true 
)

Wait for all of the specified Thread Flags to become signaled for the current thread.

Parameters
flagsspecifies the flags to wait for
millisecabsolute timeout time, referenced to Kernel::get_ms_count()
clearwhether to clear the specified flags after waiting for them. (default: true)
Returns
actual thread flags before clearing, which may not satisfy the wait
Note
You cannot call this function from ISR context.
the underlying RTOS may have a limit to the maximum wait time due to internal 32-bit computations, but this is guaranteed to work if the wait is <= 0x7fffffff milliseconds (~24 days). If the limit is exceeded, the wait will time out earlier than specified.
See also
Thread::flags_set
Deprecated:
Pass a chrono time_point, not an integer millisecond count. For example use Kernel::Clock::now() + 5s rather than Kernel::get_ms_count() + 5000.

◆ flags_wait_all_until() [2/2]

uint32_t flags_wait_all_until ( uint32_t  flags,
Kernel::Clock::time_point  abs_time,
bool  clear = true 
)

Wait for all of the specified Thread Flags to become signaled for the current thread.

Parameters
flagsspecifies the flags to wait for
abs_timeabsolute timeout time, referenced to Kernel::Clock
clearwhether to clear the specified flags after waiting for them. (default: true)
Returns
actual thread flags before clearing, which may not satisfy the wait
Note
You cannot call this function from ISR context.
the underlying RTOS may have a limit to the maximum wait time due to internal 32-bit computations, but this is guaranteed to work if the wait is <= 0x7fffffff milliseconds (~24 days). If the limit is exceeded, the wait will time out earlier than specified.
See also
Thread::flags_set

◆ flags_wait_any_for() [1/2]

uint32_t flags_wait_any_for ( uint32_t  flags,
uint32_t  millisec,
bool  clear = true 
)

Wait for any of the specified Thread Flags to become signaled for the current thread.

Parameters
flagsspecifies the flags to wait for
millisectimeout value.
clearwhether to clear the specified flags after waiting for them. (default: true)
Returns
actual thread flags before clearing, which may not satisfy the wait
Note
You cannot call this function from ISR context.
See also
Thread::flags_set
Deprecated:
Pass a chrono duration, not an integer millisecond count. For example use 5s rather than 5000.

◆ flags_wait_any_for() [2/2]

uint32_t flags_wait_any_for ( uint32_t  flags,
Kernel::Clock::duration_u32  rel_time,
bool  clear = true 
)

Wait for any of the specified Thread Flags to become signaled for the current thread.

Parameters
flagsspecifies the flags to wait for
rel_timetimeout value.
clearwhether to clear the specified flags after waiting for them. (default: true)
Returns
actual thread flags before clearing, which may not satisfy the wait
Note
You cannot call this function from ISR context.
See also
Thread::flags_set

◆ flags_wait_any_until() [1/2]

uint32_t flags_wait_any_until ( uint32_t  flags,
uint64_t  millisec,
bool  clear = true 
)

Wait for any of the specified Thread Flags to become signaled for the current thread.

Parameters
flagsspecifies the flags to wait for
millisecabsolute timeout time, referenced to Kernel::get_ms_count()
clearwhether to clear the specified flags after waiting for them. (default: true)
Returns
actual thread flags before clearing, which may not satisfy the wait
Note
You cannot call this function from ISR context.
the underlying RTOS may have a limit to the maximum wait time due to internal 32-bit computations, but this is guaranteed to work if the wait is <= 0x7fffffff milliseconds (~24 days). If the limit is exceeded, the wait will time out earlier than specified.
See also
Thread::flags_set
Deprecated:
Pass a chrono time_point, not an integer millisecond count. For example use Kernel::Clock::now() + 5s rather than Kernel::get_ms_count() + 5000.

◆ flags_wait_any_until() [2/2]

uint32_t flags_wait_any_until ( uint32_t  flags,
Kernel::Clock::time_point  abs_time,
bool  clear = true 
)

Wait for any of the specified Thread Flags to become signaled for the current thread.

Parameters
flagsspecifies the flags to wait for
abs_timeabsolute timeout time, referenced to Kernel::Clock
clearwhether to clear the specified flags after waiting for them. (default: true)
Returns
actual thread flags before clearing, which may not satisfy the wait
Note
You cannot call this function from ISR context.
the underlying RTOS may have a limit to the maximum wait time due to internal 32-bit computations, but this is guaranteed to work if the wait is <= 0x7fffffff milliseconds (~24 days). If the limit is exceeded, the wait will time out earlier than specified.
See also
Thread::flags_set

◆ sleep_for() [1/2]

void sleep_for ( uint32_t  millisec)

Sleep for a specified time period in millisec:

Parameters
millisectime delay value
Note
You cannot call this function from ISR context.
The equivalent functionality is accessible in C via thread_sleep_for.
Deprecated:
Pass a chrono duration, not an integer millisecond count. For example use 5s rather than 5000.

◆ sleep_for() [2/2]

void sleep_for ( Kernel::Clock::duration_u32  rel_time)

Sleep for a specified time period:

Parameters
rel_timetime delay value
Note
You cannot call this function from ISR context.
The equivalent functionality is accessible in C via thread_sleep_for.

◆ sleep_until() [1/2]

void sleep_until ( uint64_t  millisec)

Sleep until a specified time in millisec The specified time is according to Kernel::get_ms_count().

Parameters
millisecabsolute time in millisec
Note
You cannot call this function from ISR context.
if millisec is equal to or lower than the current tick count, this returns immediately.
The equivalent functionality is accessible in C via thread_sleep_until.
Deprecated:
Pass a chrono time_point, not an integer millisecond count. For example use Kernel::Clock::now() + 5s rather than Kernel::get_ms_count() + 5000.

◆ sleep_until() [2/2]

void sleep_until ( Kernel::Clock::time_point  abs_time)

Sleep until a specified time in millisec The specified time is according to Kernel::Clock.

Parameters
abs_timeabsolute time
Note
You cannot call this function from ISR context.
if abs_time is equal to or lower than Kernel::Clock::now(), this returns immediately.
The equivalent functionality is accessible in C via thread_sleep_until.

◆ yield()

void yield ( )

Pass control to next equal-priority thread that is in state READY.

(Higher-priority READY threads would prevent us from running; this will not enable lower-priority threads to run, as we remain READY).

Note
You cannot call this function from ISR context.

◆ get_id()

osThreadId_t get_id ( )

Get the thread id of the current running thread.

Returns
thread ID for reference by other functions or nullptr in case of error or in ISR context.
Note
You may call this function from ISR context.

◆ get_name()

const char * get_name ( )

Get the thread name of the current running thread.

Returns
thread name pointer or nullptr if thread has no name or in case of error.
Note
You cannot call this function from ISR context.