diff options
| author | Shell <[email protected]> | 2024-05-08 09:22:09 +0800 |
|---|---|---|
| committer | GitHub <[email protected]> | 2024-05-08 09:22:09 +0800 |
| commit | 6977cf91013724b8bf632cf4ad08f8dbb0392fb2 (patch) | |
| tree | 00bb4f5b9bf00714b8176db4fced2e09e096d6f5 /src/cpu_mp.c | |
| parent | 02e0334ac3dacca463c36bcbb7f71b0f35c2af85 (diff) | |
[src] add rt_hw_cpu_id() wrapper API (#8894)
* [src] add rt_hw_cpu_id() wrapper API
rt_hw_cpu_id() is an unsafe API which should not be used by most codes
directly. It's error-prone because it must be used in proper context,
otherwise it can lead to errors and unpredictable behavior.
This patch adds a wrapper API for rt_hw_cpu_id() to address this risk.
It includes the context-checking functionality and provides a safer
alternative for obtaining CPU IDs, ensuring that it is used correctly
within the appropriate context.
Signed-off-by: Shell <[email protected]>
* fixup UMP
* update API & comment
* ci: cpp_check
---------
Signed-off-by: Shell <[email protected]>
Diffstat (limited to 'src/cpu_mp.c')
| -rw-r--r-- | src/cpu_mp.c | 17 |
1 files changed, 17 insertions, 0 deletions
diff --git a/src/cpu_mp.c b/src/cpu_mp.c index c27374707c..8da4c3e180 100644 --- a/src/cpu_mp.c +++ b/src/cpu_mp.c @@ -216,3 +216,20 @@ void rt_cpus_lock_status_restore(struct rt_thread *thread) rt_sched_post_ctx_switch(thread); } RTM_EXPORT(rt_cpus_lock_status_restore); + +/* A safe API with debugging feature to be called in most codes */ + +/** + * @brief Get logical CPU ID + * + * @return logical CPU ID + */ +rt_base_t rt_cpu_get_id(void) +{ + + RT_ASSERT(rt_sched_thread_is_binding(RT_NULL) || + rt_hw_interrupt_is_disabled() || + !rt_scheduler_is_available()); + + return rt_hw_cpu_id(); +} |
