Mistake on this page?
Report an issue in GitHub or email us
Functions
rtos::ThisThread Namespace Reference

The ThisThread namespace allows controlling the current thread. More...

Functions

uint32_t flags_clear (uint32_t flags)
 Clears the specified Thread Flags of the currently running 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

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();
}

Function Documentation

uint32_t rtos::ThisThread::flags_clear ( uint32_t  flags)

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
uint32_t rtos::ThisThread::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
uint32_t rtos::ThisThread::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
uint32_t rtos::ThisThread::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.
uint32_t rtos::ThisThread::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
uint32_t rtos::ThisThread::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.
uint32_t rtos::ThisThread::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
uint32_t rtos::ThisThread::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
uint32_t rtos::ThisThread::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.
uint32_t rtos::ThisThread::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
uint32_t rtos::ThisThread::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.
uint32_t rtos::ThisThread::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
osThreadId_t rtos::ThisThread::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.
const char* rtos::ThisThread::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.
void rtos::ThisThread::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.
void rtos::ThisThread::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.
void rtos::ThisThread::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.
void rtos::ThisThread::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.
void rtos::ThisThread::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.
Important Information for this Arm website

This site uses cookies to store information on your computer. By continuing to use our site, you consent to our cookies. If you are not happy with the use of these cookies, please review our Cookie Policy to learn how they can be disabled. By disabling cookies, some features of the site will not work.