当前位置:  技术问答>linux和unix

谁帮我看下宏定义 这个宏定义我看不懂 关于等待队列的

    来源: 互联网  发布时间:2016-01-27

    本文导语:  #define DECLARE_WAITQUEUE(name, tsk)    wait_queue_t name  =__WAITQUEUE_INITIALIZER(name, tsk) #define __WAITQUEUE_INITIALIZER(name, tsk) {    task:  tsk,      task_list: { NULL, NULL },   __WAITQUEUE_DEBUG_INI(name)} 它的解释是: 通过DECLARE_WAIT...

#define DECLARE_WAITQUEUE(name, tsk)   
wait_queue_t name  =__WAITQUEUE_INITIALIZER(name, tsk)
#define __WAITQUEUE_INITIALIZER(name, tsk) {    task:  tsk,      task_list: { NULL, NULL },   __WAITQUEUE_DEBUG_INI(name)}

它的解释是:
通过DECLARE_WAITQUEUE宏将等待队列项初始化成对应的任务结构,并且用于连接的相关指针均设置为空。其中加入了调试相关代码。


还是不懂 大家帮忙!!!

|
详细的用法可以参见LKD2e Chapter 4 process scheduling
Page52 ~ 53 (english edition)
Page41 ~ 41 (chinese edition)
讲得很清楚,下面列了一些内容出来。仔细看看就知道用法了。不用急。

----------------------



Sleeping is handled via wait queues. A wait queue is a simple list of processes waiting for an event to occur. Wait queues are represented in the kernel by wake_queue_head_t. Wait queues are created statically via DECLARE_WAITQUEUE() or dynamically via init_waitqueue_head(). Processes put themselves on a wait queue and mark themselves not runnable. When the event associated with the wait queue occurs, the processes on the queue are awakened. It is important to implement sleeping and waking correctly, to avoid race conditions.

Some simple interfaces for sleeping used to be in wide use. These interfaces, however, have races: It is possible to go to sleep after the condition becomes true. In that case, the task might sleep indefinitely. Therefore, the recommended method for sleeping in the kernel is a bit more complicated:

/* 'q' is the wait queue we wish to sleep on */
DECLARE_WAITQUEUE(wait, current);

add_wait_queue(q, &wait);
while (!condition) {     /* condition is the event that we are waiting for */
        set_current_state(TASK_INTERRUPTIBLE); /* or TASK_UNINTERRUPTIBLE */
        if (signal_pending(current))
                /* handle signal */
        schedule();
}
set_current_state(TASK_RUNNING);
remove_wait_queue(q, &wait);



The task performs the following steps to add itself to a wait queue:

1 Creates a wait queue entry via DECLARE_WAITQUEUE().

2 Adds itself to a wait queue via add_wait_queue(). This wait queue awakens the process when the condition for which it is waiting occurs. Of course, there needs to be code elsewhere that calls wake_up() on the queue when the event actually does occur.

3 Changes the process state to TASK_INTERRUPTIBLE or TASK_UNINTERRUPTIBLE.

4 If the state is set to TASK_INTERRUPTIBLE, a signal wakes the process up. This is called a spurious wake up (a wake-up not caused by the occurrence of the event). So check and handle signals.

5 Tests whether the condition is true. If it is, there is no need to sleep. If it is not true, the task calls schedule().

6 When the task awakens, it again checks whether the condition is true. If it is, it exits the loop. Otherwise, it again calls schedule() and repeats.

7 Now that the condition is true, the task can set itself to TASK_RUNNING and remove itself from the wait queue via remove_wait_queue().


    
 
 
 
本站(WWW.)旨在分享和传播互联网科技相关的资讯和技术,将尽最大努力为读者提供更好的信息聚合和浏览方式。
本站(WWW.)站内文章除注明原创外,均为转载、整理或搜集自网络。欢迎任何形式的转载,转载请注明出处。












  • 相关文章推荐
  • java命名空间java.awt类radialgradientpaint的类成员方法: getradius定义及介绍
  • 请问可以用宏定义定义一个二维数组吗?
  • java命名空间javax.xml.stream类xmlinputfactory成员方法: seteventallocator定义参考
  • 想修改路径定义,想找到在哪里定义的,应该怎么办?
  • java命名空间java.text接口attributedcharacteriterator的类成员方法: getallattributekeys定义及介绍
  • php定义数组和使用示例(php数组的定义方法)
  • java命名空间java.beans接口propertyeditor的类成员方法: supportscustomeditor定义及介绍
  • 上次问题解决了,原来是extern被重定义了。。。天阿,关键字也可以被重定义。。。。。欢迎接分
  • java命名空间javax.swing类jtextarea的类成员方法: getcolumnwidth定义及介绍
  • 如何定义一个可变参数的自定义函数
  • java命名空间javax.swing类jtextfield的类成员方法: getcolumnwidth定义及介绍
  • 下面的变量我都下了定义,为什么还出现没定义的信息
  • java命名空间javax.swing类actionmap的类成员方法: allkeys定义及介绍
  • oracle异常(预定义异常,自定义异常)应用介绍
  • java命名空间javax.swing类inputmap的类成员方法: allkeys定义及介绍
  • 为什么我在头文件time.h里找不到time_t的定义呢?只有这个定义typedef __time_t time_t;
  • java命名空间javax.rmi.corba接口valuehandler的类成员方法: iscustommarshaled定义及介绍
  • 函数有定义怎么提示没有低能定义的错误呢?
  • java命名空间javax.swing类jcomponent的类成员方法: resetkeyboardactions定义及介绍
  • android自定义控件和自定义回调函数步骤示例
  • java命名空间java.beans接口customizer的类成员方法: setobject定义及介绍
  • 自定义公共类的装载,包的定义


  • 站内导航:


    特别声明:169IT网站部分信息来自互联网,如果侵犯您的权利,请及时告知,本站将立即删除!

    ©2012-2021,,E-mail:www_#163.com(请将#改为@)

    c/c++开源软件 iis7站长之家