list_empty在某些迭代后返回true。

时间:2018-07-21 09:19:07

标签: linux linked-list v4l2

我正在通过从Linux内核引用vivi.c驱动程序来编写V4L2驱动程序 https://elixir.bootlin.com/linux/v3.17/source/drivers/media/platform/vivi.c#L875

static void vivi_thread_tick(struct vivi_dev *dev)
{
    struct vivi_dmaqueue *dma_q = &dev->vidq;
    struct vivi_buffer *buf;
    unsigned long flags = 0;

    dprintk(dev, 1, "Thread tick\n");

    spin_lock_irqsave(&dev->slock, flags);
    if (list_empty(&dma_q->active)) {
        dprintk(dev, 1, "No active queue to serve\n");
        spin_unlock_irqrestore(&dev->slock, flags);
        return;
    }

    buf = list_entry(dma_q->active.next, struct vivi_buffer, list);
    list_del(&buf->list);
    spin_unlock_irqrestore(&dev->slock, flags);

    v4l2_get_timestamp(&buf->vb.v4l2_buf.timestamp);

    /* Fill buffer */
    vivi_fillbuff(dev, buf);
    dprintk(dev, 1, "filled buffer %p\n", buf);

    vb2_buffer_done(&buf->vb, VB2_BUF_STATE_DONE);
    dprintk(dev, 2, "[%p/%d] done\n", buf, buf->vb.v4l2_buf.index);
}

在上面显示的vivi_thread_tick()函数中,如果(list_empty(&dma_q-> active))经过一些迭代后变为true。因此,在dmesg -w中显示“无活动队列可服务”。

调试代码后,看起来dma_q-> active.next和dma_q-> active.prev指向相同的地址。 Head,Head-> next和Head-> prev地址如下:

Sl No   Head            Head->next       Hear->prev       vb2_buffer->index
1      FFC09637B0       FFF03C19E8      FFEEEB19E8             0
2      FFF03C05E8       FFEEEB19E8      FFF03C05E8             1
3      FFF03C0DE8       FFF03C05E8      FFF03C0DE8             2
4      FFF03C19E8       FFF03C0DE8      FFF03C19E8             3
5      FFC09637B0       FFF03C19E8      FFEEEB19E8             0
6      FFF03C05E8       FFEEEB19E8      FFF03C05E8             1
7      FFF03C0DE8       FFF03C05E8      FFF03C0DE8             2
8      FFF03C19E8       FFF03C0DE8      FFF03C19E8             3
9      FFC09637B0       FFF03C19E8      FFEEEB19E8             0
10     FFF03C05E8       FFEEEB19E8      FFF03C05E8             1
11     FFF03C0DE8       FFF03C05E8      FFF03C0DE8             2
12     FFF03C19E8       FFF03C0DE8      FFF03C19E8             3
13     FFC09637B0       FFF03C19E8      FFEEEB19E8             0
14     FFF03C05E8       FFEEEB19E8      FFF03C05E8             1
15     FFF03C0DE8       FFF03C05E8      FFF03C0DE8             2
16     FFF03C19E8       FFF03C0DE8      FFF03C19E8             3
17     FFC09637B0       FFF03C19E8      FFEEEB19E8             0
18     FFF03C05E8       FFEEEB19E8      FFF03C05E8             1
19     FFF03C0DE8       FFF03C05E8      FFF03C0DE8             2
20     FFF03C19E8       FFF03C0DE8      FFF03C19E8             3
21     FFC09637B0       FFF03C19E8      FFEEEB19E8             0
22     FFC09637B0       FFF03C19E8      FFEEEB19E8             1
23     FFC09637B0       FFF03C19E8      FFF03C0DE8             2
24     FFF03C19E8       FFF03C19E8      FFF03C19E8             3
25     FFEEF038E8       FFEEF038E8      FFEEF038E8           

您可以看到序列号24和25,Head-> next和Head-> prev相同。因此(list_empty(&dma_q-> active))为true。

查询: 为什么经过一些迭代,Head-> next和Head-> prev指向相同的地址?

0 个答案:

没有答案