+ -
当前位置:首页 → 问答吧 → current宏

current宏

时间:2011-07-14

来源:互联网

在x86的<asm/current.h>中
C/C++ code
#ifndef _ASM_X86_CURRENT_H
#define _ASM_X86_CURRENT_H

#include <linux/compiler.h>
#include <asm/percpu.h>

#ifndef __ASSEMBLY__
struct task_struct;

DECLARE_PER_CPU(struct task_struct *, current_task);

static __always_inline struct task_struct *get_current(void)
{
    return percpu_read_stable(current_task);
}

#define current get_current()

#endif /* __ASSEMBLY__ */

#endif /* _ASM_X86_CURRENT_H */


percpu_read_stable(current_task)这句看不懂,从这句往后追踪,也看不懂,求解释
为什么不是通过current_thread_info得到

作者: proghua   发布时间: 2011-07-14

猜测一下,供参考:

DECLARE_PER_CPU(struct task_struct *, current_task);
----这个宏应该是声明了一个struct task_struct *类型的结构体,名字叫current_task,这个结构体应该是指示任务属性的

static __always_inline struct task_struct *get_current(void)
{
  return percpu_read_stable(current_task);
}
----这个函数需要返回一个struct task_struct *类型的结构体指针,即获取现在的任务属性,于是调用percpu_read_stable函数,这个函数的参数是刚才声明的current_task,在percpu_read_stable函数内部应该会用各种参数填充刚才声明的current_task,然后把这个current_task返回回来

作者: thefirstz   发布时间: 2011-07-14