susheel pandey
susheel pandey

Reputation: 99

__context__ attribute in Linux kernel

In the Linux kernel include/linux/compiler.h:

#define __acquire(x)    __context__(x,1)
#define __release(x)    __context__(x,-1)

Please help me to understand, in above statements what we are trying to achieve with __context__. I couldn't find its details. I came across it while understanding spinlock implementation in Linux kernel.

Upvotes: 6

Views: 1735

Answers (1)

Gireesh
Gireesh

Reputation: 54

As from 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.

Upvotes: 1

Related Questions