重要宏收录

来源:互联网 发布:程序员去哪个招聘网站 编辑:程序博客网 时间:2024/06/05 04:28

#define ACCESS_ONCE(x) (*(volatile typeof(x) *)&(x))


//volatile确保不被编译器优化省略,且每次必须直接从内存读值




#define DEFINE_PER_THREAD(type, name) \
        struct { \
                __typeof__(type) v \
                        __attribute__((__aligned__(CAA_CACHE_LINE_SIZE))); \
        } __per_thread_##name[NR_THREADS];


//__typeof__,返回参数的类型,详细参考:http://pic.dhe.ibm.com/infocenter/iseries/v7r1m0/index.jsp?topic=%2Frzarg%2Ftypeof_operator.htm


//__attribute__、__aligned__组合,用来指定参数的特殊属性,详细参考:http://www.delorie.com/gnu/docs/gcc/gcc_62.html


//关于__attribute__的单独详细介绍,参见:http://www.unixwiz.net/techtips/gnu-c-attributes.html


//CAA_CACHE_LINE_SIZE宏,是CPU cache line的大小,获取方法见 ”Cross-platform function to get your cache line size “ 一文


//NR_THREADS宏,线程数





#define DECLARE_PER_THREAD(type, name) extern DEFINE_PER_THREAD(type, name)




#ifdef CONFIG_SMP

#define LOCK_PREFIX \
        ".section .smp_locks,\"a\"\n"    \
        "  .align 4\n"            \
"  .long 661f\n" /* address */    \
".previous\n"            \
"661:\n\tlock"

#else /* ! CONFIG_SMP */
#define LOCK_PREFIX ""
#endif


//LOCK_PREFIX 宏定义了 lock 指令前缀,在单处理器系统下,LOCK_PREFIX 宏为空,因为此时并不需要 lock 指令前缀,处理器只要有可能,原子操作就会被编译成单个机器指令。

//lock为指令前缀,可以使lock引脚变成逻辑0,在lock引脚有效期间,禁止外部总线上的其它处理器存取带有lock前缀指令的存储器操作数。