summaryrefslogtreecommitdiff
path: root/include
diff options
context:
space:
mode:
authorShell <[email protected]>2024-05-08 09:22:09 +0800
committerGitHub <[email protected]>2024-05-08 09:22:09 +0800
commit6977cf91013724b8bf632cf4ad08f8dbb0392fb2 (patch)
tree00bb4f5b9bf00714b8176db4fced2e09e096d6f5 /include
parent02e0334ac3dacca463c36bcbb7f71b0f35c2af85 (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 'include')
-rw-r--r--include/rtthread.h29
1 files changed, 26 insertions, 3 deletions
diff --git a/include/rtthread.h b/include/rtthread.h
index b73f63f38a..9cc0c4d879 100644
--- a/include/rtthread.h
+++ b/include/rtthread.h
@@ -676,11 +676,19 @@ void rt_interrupt_leave(void);
rt_base_t rt_cpus_lock(void);
void rt_cpus_unlock(rt_base_t level);
+void rt_cpus_lock_status_restore(struct rt_thread *thread);
struct rt_cpu *rt_cpu_self(void);
struct rt_cpu *rt_cpu_index(int index);
-void rt_cpus_lock_status_restore(struct rt_thread *thread);
+#ifdef RT_USING_DEBUG
+ rt_base_t rt_cpu_get_id(void);
+#else /* !RT_USING_DEBUG */
+ #define rt_cpu_get_id rt_hw_cpu_id
+#endif /* RT_USING_DEBUG */
+
+#else /* !RT_USING_SMP */
+#define rt_cpu_get_id() (0)
#endif /* RT_USING_SMP */
@@ -781,7 +789,6 @@ while (0)
* 1) the scheduler has been started.
* 2) not in interrupt context.
* 3) scheduler is not locked.
- * 4) interrupt is not disabled.
*/
#define RT_DEBUG_SCHEDULER_AVAILABLE(need_check) \
do \
@@ -809,11 +816,27 @@ rt_inline rt_bool_t rt_in_thread_context(void)
return rt_thread_self() != RT_NULL && rt_interrupt_get_nest() == 0;
}
+/* is scheduler available */
rt_inline rt_bool_t rt_scheduler_is_available(void)
{
- return !rt_hw_interrupt_is_disabled() && rt_critical_level() == 0 && rt_in_thread_context();
+ return rt_critical_level() == 0 && rt_in_thread_context();
+}
+
+#ifdef RT_USING_SMP
+/* is thread bond on core */
+rt_inline rt_bool_t rt_sched_thread_is_binding(rt_thread_t thread)
+{
+ if (thread == RT_NULL)
+ {
+ thread = rt_thread_self();
+ }
+ return !thread || RT_SCHED_CTX(thread).bind_cpu != RT_CPUS_NR;
}
+#else
+#define rt_sched_thread_is_binding(thread) (RT_TRUE)
+#endif
+
/**@}*/
#ifdef __cplusplus