每个进程有两个独立的状态标志:
task->state:是关系进程的 runnability;
task->exit_state:是关于 task exiting;
#define TASK_RUNNING 0
#define TASK_INTERRUPTIBLE 1
#define TASK_UNITERRUPTIBLE 2
#define __TASK_STOPPED 4
#define __TASK_TRACED 8
/* in task->exit_state*/
#define EXIT_ZOMBIE 16
#define EXIT_DEAD 32
/*in task->state*/
#define TASK_DEAD 64
#define TASK_WAKEKILL 128
#define TASK_WAKING 256
set_task_state()函数中用到的符号常量的宏定义:
#define TASK_KILLABLE (TASK_WAKEKILL | TASK_UNINTERRUPTIBLE)
#define TASK_STOPPED (TASK_WAKEKILL | __TASK_STOPPED)
#define TASK_TRACED (TASK_WAKEKILL | __TASK_TRACED)
wake_up()函数中用到的符号常量的宏定义:
#define TASK_NORMAL (TASK_INTERRUPTIBLE | TASK_UNITERRUPTIBLE)
#define TASK_ALL (TASK_NORMAL | __TASK_STOPPED | __TASK_TRACED)
get_task_state()函数中用到的符号常量的宏定义:
#define TASK_REPORT (TASK_RUNNING | TASK_INTERRUPTIBLE \
| TASK_UNINTERRUPTIBLE | __TASK_STOPPED\
| __TASK_TRACED)
set_task_state()方法的实现:
#define set_task_state(task, state_value) \
set_mb((task)->state, (state_value))
set_mb()函数保证了指令的执行顺序;
#define __set_task_state(task, state_value) \
do{ (task)->state = (state_value );}while(0)
set_current_stat()方法的实现:
#define __set_current_state(state_value) \
do{ current->state = (state_value);}while(0)
#define set_current_state(state_value) \
set_mb(current->state, (state_value))