We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
当需要高性能时,atomic操作,无锁操作是至关重要的。在RT-Thread中引入atomic可以是这样:
软
rtdef.h中
rtdef.h
#if defined(RT_USING_STD_ATOMIC) #include <stdatomic.h> typedef atomic_size_t rt_atomic_t; #else typedef volatile rt_base_t rt_atomic_t; #endif
rtthread.h中
rtthread.h
#if defined(RT_USING_HW_ATOMIC) #define rt_atomic_add(ptr, v) rt_hw_atomic_add(ptr, v) /* 宏定义到libcpu下的hw_atomic实现 */ #elif defined(RT_USING_STD_ATOMIC) #define rt_atomic_add(ptr, v) atomic_fetch_add(ptr, v) /* 宏定义到c11中的atomic实现 */ #else #endif
具体实现,开关中断方式软实现 atomic.c in rt-thread/src
atomic.c
rt-thread/src
否则,
参考PR
The text was updated successfully, but these errors were encountered:
赞成赞成
Sorry, something went wrong.
c11的atomic详细说明:
https://github.com/zenny-chen/C11-atomic-operations-in-detail
对于RT-Thread来说,atomic类型会取atomic_size_t,即和处理器位宽相关的类型(标准类型对应到size_t)。
atomic_size_t
size_t
#include <stdatomic.h> typedef atomic_size_t rt_atomic_t; #define rt_atomic_add(ptr, v) atomic_fetch_add(ptr, v) #define rt_atomic_sub(ptr, v) atomic_fetch_sub(ptr, v) #define rt_atomic_or(ptr, v) atomic_fetch_or(ptr, v) #define rt_atomic_xor(ptr, v) atomic_fetch_xor(ptr, v) #define rt_atomic_and(ptr, v) atomic_fetch_and(ptr, v) #define rt_atomic_cas(ptr, v, d) atomic_compare_exchange_strong(ptr, v, d) #define rt_atomic_set(ptr, v) atomic_store(ptr, v) #define rt_atomic_get(ptr) atomic_load(ptr)
对于size_t来说,后续也需要在rt_kprintf中加入%zd的支持。
%zd
No branches or pull requests
当需要高性能时,atomic操作,无锁操作是至关重要的。在RT-Thread中引入atomic可以是这样:
软
实现rtdef.h
中rtthread.h
中具体实现,开关中断方式
软
实现atomic.c
inrt-thread/src
否则,
参考PR
The text was updated successfully, but these errors were encountered: