|
Files | |
| file | sleep.h |
| Defines thread sleep primitives. | |
Macros | |
| #define | SYS_THREAD_CAPACITY 16 |
| Maximum number of concurrently active thread contexts in static-pool implementations. | |
Typedefs | |
| typedef void(* | sys_thread_func_t) (void *arg) |
| Thread function signatureFunction signature for thread entry points. More... | |
Functions | |
| void | sys_sleep_ms (uint32_t ms) |
| Pauses the current thread for a specified duration. More... | |
Methods | |
| uint8_t | sys_thread_numcores (void) |
| Returns the number of CPU cores available on the host system. More... | |
| bool | sys_thread_create (sys_thread_func_t func, void *arg) |
| Create a thread on any available core. More... | |
| bool | sys_thread_create_on_core (sys_thread_func_t func, void *arg, uint8_t core) |
| Create a thread on a specific core. More... | |
| uint8_t | sys_thread_core (void) |
| Get the CPU core number the current thread is running on. More... | |
The SystemThread module provides lightweight cross-platform helpers for creating fire-and-forget worker threads and querying CPU core information.
Thread creation APIs (sys_thread_create, sys_thread_create_on_core) execute a user callback with a single opaque argument and return immediately after the worker is scheduled. Workers terminate when the callback returns.
Core-query APIs (sys_thread_numcores, sys_thread_core) support adaptive scheduling decisions and diagnostics for multicore execution.
Typical flow:
sys_thread_numcores().sys_thread_create*().sys_thread_core().Notes:
SYS_THREAD_CAPACITY. | typedef void(* sys_thread_func_t) (void *arg) |
| void sys_sleep_ms | ( | uint32_t | ms | ) |
Pauses the current thread for a specified duration.
| ms | The number of milliseconds to sleep. |
This function blocks only the calling thread for approximately the requested duration.
| uint8_t sys_thread_core | ( | void | ) |
Get the CPU core number the current thread is running on.
This function queries the system to determine which CPU core the calling thread is currently scheduled on. Note that threads may migrate between cores, so this value may change over time unless thread affinity is set.
| bool sys_thread_create | ( | sys_thread_func_t | func, |
| void * | arg | ||
| ) |
Create a thread on any available core.
| func | Function to execute in the new thread |
| arg | Argument to pass to the thread function |
Creates a new thread that executes the specified function with the given argument. The thread runs independently and terminates when the function returns. No cleanup or joining is required - the thread is fire-and-forget. On systems with multiple cores, the thread may be scheduled on any available core. Implementations that use a static thread context pool may return false after SYS_THREAD_CAPACITY concurrent threads have been created.
| bool sys_thread_create_on_core | ( | sys_thread_func_t | func, |
| void * | arg, | ||
| uint8_t | core | ||
| ) |
Create a thread on a specific core.
| func | Function to execute in the new thread |
| arg | Argument to pass to the thread function |
| core | Core number to run the thread on (0-based) |
Creates a new thread that executes the specified function on a specific CPU core. The thread runs independently and terminates when the function returns. If the specified core is not available or already in use, the function returns false. Core 0 is typically the main/boot core. Implementations that use a static thread context pool may return false after SYS_THREAD_CAPACITY concurrent threads have been created.
| uint8_t sys_thread_numcores | ( | void | ) |
Returns the number of CPU cores available on the host system.
This function queries the system to determine the total number of processing cores available.