PROCESS宏定义在core\sys的process.h文件内,如下:
-
#define PROCESS(name, strname) \
-
PROCESS_THREAD(name, ev, data); \
-
struct process name = { NULL, strname, \
-
process_thread_##name }
-
#define PROCESS_THREAD(name, ev, data) \
-
static PT_THREAD(process_thread_##name(struct pt *process_pt, \
-
process_event_t ev, \
-
process_data_t data))
-
#define PT_THREAD(name_args) char name_args
-
#define AUTOSTART_PROCESSES(...) \
-
struct process * const autostart_processes[] = {__VA_ARGS__, NULL}
-
#define PROCESS_BEGIN() PT_BEGIN(process_pt)
-
#define PT_BEGIN(pt) { char PT_YIELD_FLAG = 1; LC_RESUME((pt)->lc)
-
#define LC_RESUME(s) switch(s) { case 0:
把参数替换,结果如下:
-
{
-
char PT_YIELD_FLAG = 1; /*将PT_YIELD_FLAG置1,类似于关中断???*/
-
switch(process_pt->lc) /*程序根据lc的值进行跳转,lc用于保存程序断点*/
-
{
-
case 0: /*第一次执行从这里开始,可以放一些初始化的东东*/
-
;
-
#define PROCESS_END() PT_END(process_pt)
-
#define PT_END(pt) LC_END((pt)->lc); PT_YIELD_FLAG = 0; \ PT_INIT(pt); return PT_ENDED; }
-
#define LC_END(s) }
-
#define PT_INIT(pt) LC_INIT((pt)->lc)
-
#define LC_INIT(s) s = 0;
-
#define PT_ENDED 3
-
-
把参数替换,结果如下:
-
}
-
PT_YIELD_FLAG = 0;
-
(process_pt)->lc = 0;
-
-
return 3;
-
}
-
/*即进程主动让出执行权*/
-
#define PROCESS_YIELD() PT_YIELD(process_pt)
-
#define LC_SET(s) s = __LINE__; case __LINE__: /*保存被中断的行数*/
-
-
/*继续展开如下,Yield from the current protothread*/
-
#define PT_YIELD(pt) \
-
do { \
-
PT_YIELD_FLAG = 0; \
-
LC_SET((pt)->lc); \
-
if(PT_YIELD_FLAG == 0) { \
-
return PT_YIELDED; \
-
} \
-
} while(0)
// 把参数替换,结果如下:
-
do {
-
PT_YIELD_FLAG = 0;
-
(process_pt)->lc = __LINE__;
-
case __LINE__:
-
if(PT_YIELD_FLAG == 0) {
-
return PT_YIELDED;
-
}
-
} while(0)
阅读(1152) | 评论(0) | 转发(0) |