在内核\include\linux\compiler.h
#define __acquire(x) __context__(x,1)
#define __release(x) __context__(x,-1)
请帮助我理解,在上述声明中,我们试图通过 实现什么上下文 .我找不到它的详细信息。
我在理解 linux 内核中的自旋锁实现时越过了它。
最佳答案
来自 http://linux.die.net/man/1/sparse :
-Wcontext Warn about potential errors in synchronization or other delimited contexts. Sparse supports several means of designating functions or statements that delimit contexts, such as synchronization. Functions with the extended attribute attribute((context(expression,in_context,out_context)) require the context expression (for instance, a lock) to have the value in_context (a constant nonnegative integer) when called, and return with the value out_context (a constant nonnegative integer). For APIs defined via macros, use the statement form context(expression,in_value,out_value) in the body of the macro.
With -Wcontext Sparse will warn when it sees a function change the context without indicating this with a context attribute, either by decreasing a context below zero (such as by releasing a lock without acquiring it), or returning with a changed context (such as by acquiring a lock without releasing it). Sparse will also warn about blocks of code which may potentially execute with different contexts.
Sparse issues these warnings by default. To turn them off, use -Wno-context.
关于linux-kernel - linux 内核中的 __context__ 属性,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28555143/