contiki中关于进程的开始与挂起等相关函数的说明与小结

来源:互联网 发布:免费商城源码哪个好 编辑:程序博客网 时间:2024/06/06 08:23

首先,还是把相关函数都列出来

PROCESS_BEGIN()          // Define the beginning of a process.  PROCESS_END()             //  Define the end of a process. 

PROCESS_EXIT()         //Exit the currently running process.
process_exit(struct process *p)    //Cause a process to exit. 
exit_process(struct process *p, struct process *fromprocess)

PROCESS_WAIT_EVENT()             //Wait for an event to be posted to the process. 
PROCESS_WAIT_EVENT_UNTIL(c)      //Wait for an event to be posted to the process, with an extra condition. PROCESS_YIELD()                  //Yield the currently running process.  PROCESS_YIELD_UNTIL(c)           //Yield the currently running process until a condition occurs.PROCESS_WAIT_UNTIL(c)            //Wait for a condition to occur.  PROCESS_WAIT_WHILE(c)            //PT_WAIT_WHILE(process_pt, c)  PROCESS_PT_SPAWN(pt, thread)      //Spawn a protothread from the process.  PROCESS_PAUSE()                   //Yield the process for a short while.


int process_post (struct process *p, process_event_t ev, void *data)                                 //Post an asynchronous event.  void process_post_synch (struct process *p, process_event_t ev, void *data)                          //Post a synchronous event to a process.
process_poll(process_ptr)


上面的基本上是关于进程的相关函数。还有的话,在补充。如有不足,敬请告知、

下面我讲一下我自己使用过程中遇到的一些技巧或者用法。

1、

PROCESS_BEGIN()          // Define the beginning of a process.  PROCESS_END()             //  Define the end of a process.  
这两个函数必须成对使用。这跟contiki 有关。如需更深入了解,请耐心读一下源代码。

在使用过程中,有一些小技巧。一般来讲,PROCESS_BEGIN()后面紧跟一些初始化话代码(只执行一次),初始化之后while(1),后面在跟 PROCESS_END().

2、

2.1

process_post() <pre name="code" class="objc">process_post_synch 
前一个函数是只是把事件扔进一个事件队列里面去,然后再通过do_event()函数来轮询相应的事件传递给相应的process并让其执行;后一个函数是直接让这个进程执行,相比于前一个来说,具有更高的优先级;

2.2

process_poll(process_ptr)
<span style="font-size:18px; font-family: Arial, Helvetica, sans-serif; background-color: rgb(255, 255, 255);"></span>

假如一个process被poll(其实就是process的needspoll变量被设为1)了,在执行的过程中比Post an Event具有更先执行的机会,process就不会参与事件队列的轮询,而被直接率先执行。比如etimer_process。


3、进程的退出机制。

我这边列了几个用到比较多的。

<span style="font-size:18px;"><strong>PROCESS_EXIT()         //Exit the currently running process.</strong></span>
<span style="font-size:18px;"><strong>process_exit(struct process *p)    //Cause a process to exit. </strong></span>
<span style="font-size:18px;"><strong>exit_process(struct process *p, struct process *fromprocess)</strong></span>

PROCESS_EXIT()   退出当前的进程

process_exit()    退出其它进程

exit_process()  里面的两个参数,起一个是需要退出的进程,后一个表示当前的进程。我在用这个函数退出本进程的时候,出现了一点小问题,建议不要退出当前进程。里面的机理还不是很明白。还望网友请教。


4、如果一个进程,我们并不想退出,只是一个挂起或者等待其它事件,那么我们需要用到下面的函数

<strong>PROCESS_WAIT_EVENT()             //Wait for an event to be posted to the process. </strong>
<strong>PROCESS_WAIT_EVENT_UNTIL(c)      //Wait for an event to be posted to the process, with an extra condition. PROCESS_YIELD()                  //Yield the currently running process.  PROCESS_YIELD_UNTIL(c)           //Yield the currently running process until a condition occurs.PROCESS_WAIT_UNTIL(c)            //Wait for a condition to occur.  PROCESS_WAIT_WHILE(c)            //PT_WAIT_WHILE(process_pt, c)  PROCESS_PT_SPAWN(pt, thread)      //Spawn a protothread from the process.  PROCESS_PAUSE()                   //Yield the process for a short while.</strong>
说明几个比较常用的函数
PROCESS_WAIT_EVENT() 使用这个函数挂起的时候,如果需要再次执行这个进程的时候,需要一个post。如何post,参考2.1 2.2
PROCESS_WAIT_EVENT_UNTIL(c) 这个函数不仅仅需要PROCESS_WAIT_EVENT()  的条件成立,还需要c成立才会执行下面的代码。特别注意的是,如果条件是跟etimer有关的话,可以不用手动 post。
其它的函数,基本上都跟这两个函数有关,或者差不多。这边就不多讲了。需要的话么可以自己看代码。
参考文献:

http://blog.chinaunix.net/uid-23117778-id-3371749.html

里面的内容如有不适,敬请告知

如有错误,希望网友告知,可在帖子下面回复









0 0