what does “static int function(…) __acquires(..) __releases(…){” mean?
来源:互联网 发布:八实万是网络传销吗 编辑:程序博客网 时间:2024/06/01 11:52
http://stackoverflow.com/questions/21018778/what-does-static-int-function-acquires-releases-mean
I recently got a snippet of code in Linux kernel:
static intfb_mmap(struct file *file, struct vm_area_struct * vma)__acquires(&info->lock)__releases(&info->lock){...}
What confused me is the two __funtions following static int fb_mmap()
right before"{"
,
a).
What are the purpose of the two __funtions?
b).
Why in that position?
c).
Why do they have the prefix "__"
?
d).
Is there other examples similar to this?
Not everything ending with a pair of parenthesis is a function (call). In this case they are parameterized macro expansions. The macros are defined as
#define __acquires(x) __attribute__((context(x,0,1)))#define __releases(x) __attribute__((context(x,1,0)))
in file include/linux/compiler.h
in the kernel build tree.
The purpose of those macros expanding into attribute definitions is to annotate the function symbols with information about whichlocking structures the function will acquire (i.e. lock) and release (i.e. unlock). The purpose of those in particular is debugging locking mechanisms (the Linux kernel contains some code that allows it to detect potential deadlock situations and report on this).
https://en.wikipedia.org/wiki/Sparse
__attribute__
is a keyword specific to the GCC compiler, that allows to assign, well, attributes to a given symbolhttp://gcc.gnu.org/onlinedocs/gcc/Function-Attributes.html#Function-Attributes
Since macros are expanded at the text level, before the compiler is even looking at it, the result for your particular snippet, that the actual compilers sees would be
static intfb_mmap(struct file *file, struct vm_area_struct * vma)__attribute__((context(&info->lock,0,1)))__attribute__((context(&info->lock,1,0))){…}
Those macros start with a double underscore __
to indicate, that they are part of the compiler environment. All identifiers starting with one or two underscores are reserved for the compiler environment implementation. In the case of the Linux kernel, because Linux is a operating system kernel that does not (because it simply is not availible) use the standard library, it's natural for it, do define it's own compiler environment definitions, private to it. Hence the two underscores to indicate, that this is compiler environment/implementation specific stuff.
- what does “static int function(…) __acquires(..) __releases(…){” mean?
- What does _imp_<Function> mean?
- What does int argc, char *argv[] mean?
- What does "size" in int(size) of MySQL mean?
- What does backend type static mean in Magento?
- what does boinc mean?
- what does "ERP" mean
- What does "V"mean
- What does "Vanilla" mean ?
- What does 2>&1 mean?
- What does operator “dot” (.) mean?
- what does the three dots in “doInBackground(URL… urls)” mean?
- What does it mean to write `static void * ptr = &ptr` in objective-c?
- What does mean RSS, Atom, OPML...?
- What does Keyword-Driven Testing mean?
- What does TCP Zero Window mean?
- What does (Aborted) mean in HttpWatch?
- What does "#! /usr/bin/ksh" mean?
- With Encryption
- spring tool suite安装不进去
- C语言的类型,字节,还有转义字符0728
- [Cloud Computing]Mechanisms: Virtual Appliance
- UVA1584 UVALive3225 Circular Sequence
- what does “static int function(…) __acquires(..) __releases(…){” mean?
- 几种常见的算法
- linux常用管理命令
- 你的平庸,是当你失去信心的美好
- 微信接口 自定义菜单
- BAPI_RESERVATION_CREATE1 WEMPF 创建预留收货方问题
- Cache基础知识总结
- POJ The Pilots Brothers' refrigerator 2965
- POJ 3641 Pseudoprime numbers 【快速幂】