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.
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. |
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 32 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 39 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 75 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 or 0 in case of no time-out. 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 80 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 85 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 90 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 or 0 in case of no time-out. 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 95 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 100 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 NULL in case of error or in ISR context.
- Note:
- You may call this function from ISR context.
Definition at line 136 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.
Definition at line 105 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.
Definition at line 111 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 131 of file ThisThread.cpp.
Generated on Tue Aug 9 2022 00:37:39 by
