Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependents: TYBLE16_simple_data_logger TYBLE16_MP3_Air
rtos::ThisThread Namespace Reference
[ThisThread namespace]
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. | |
uint32_t | flags_get () |
Returns the Thread Flags currently set for the currently running thread. | |
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. | |
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. | |
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. | |
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. | |
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. | |
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. | |
void | sleep_for (uint32_t millisec) |
Sleep for a specified time period in millisec: | |
void | sleep_until (uint64_t millisec) |
Sleep until a specified time in millisec The specified time is according to Kernel::get_ms_count(). | |
void | yield () |
Pass control to next equal-priority thread that is in state READY. | |
osThreadId_t | get_id () |
Get the thread id of the current running thread. | |
const char * | get_name () |
Get the thread name of the current running thread. |
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)); ThisThread::sleep_for(5000); thread.signal_set(STOP_FLAG); thread.join(); }
Function Documentation
uint32_t flags_clear | ( | uint32_t | flags ) |
Clears the specified Thread Flags of the currently running thread.
- Parameters:
-
flags specifies 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
Definition at line 53 of file ThisThread.cpp.
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
Definition at line 64 of file ThisThread.cpp.
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:
-
flags specifies the flags to wait for clear whether 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
Definition at line 159 of file ThisThread.cpp.
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:
-
flags specifies the flags to wait for millisec timeout value. clear whether 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
Definition at line 164 of file ThisThread.cpp.
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:
-
flags specifies the flags to wait for millisec absolute timeout time, referenced to Kernel::get_ms_count() clear whether 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
Definition at line 169 of file ThisThread.cpp.
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:
-
flags specifies the flags to wait for clear whether 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
Definition at line 174 of file ThisThread.cpp.
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:
-
flags specifies the flags to wait for millisec timeout value. clear whether 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
Definition at line 179 of file ThisThread.cpp.
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:
-
flags specifies the flags to wait for millisec absolute timeout time, referenced to Kernel::get_ms_count() clear whether 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
Definition at line 184 of file ThisThread.cpp.
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.
Definition at line 232 of file ThisThread.cpp.
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.
Definition at line 241 of file ThisThread.cpp.
void sleep_for | ( | uint32_t | millisec ) |
Sleep for a specified time period in millisec:
- Parameters:
-
millisec time delay value
- Note:
- You cannot call this function from ISR context.
- The equivalent functionality is accessible in C via thread_sleep_for.
Definition at line 189 of file ThisThread.cpp.
void sleep_until | ( | uint64_t | millisec ) |
Sleep until a specified time in millisec The specified time is according to Kernel::get_ms_count().
- Parameters:
-
millisec absolute 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.
Definition at line 199 of file ThisThread.cpp.
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.
Definition at line 223 of file ThisThread.cpp.
Generated on Tue Jul 12 2022 13:55:45 by
