谁能帮助我理解“DECLARE_COMPLETION_ONSTACK”和静态(DECLARE_COMPLETION(comp))或动态初始化之间的区别?
我找到了一些引用资料,如下所示(http://lxr.free-electrons.com/source/drivers/spi/spidev.c#L110):
110 spidev_sync(struct spidev_data *spidev, struct spi_message *message)
111 {
112 DECLARE_COMPLETION_ONSTACK(done);
113 int status;
114
115 message->complete = spidev_complete;
116 message->context = &done;
117
118 spin_lock_irq(&spidev->spi_lock);
119 if (spidev->spi == NULL)
120 status = -ESHUTDOWN;
121 else
122 status = spi_async(spidev->spi, message);
123 spin_unlock_irq(&spidev->spi_lock);
124
125 if (status == 0) {
126 wait_for_completion(&done);
127 status = message->status;
128 if (status == 0)
129 status = message->actual_length;
130 }
131 return status;
132 }
看起来这里是在等待 spi_sync() 函数完成,我在理解上述函数时有几个疑问
2:这是否意味着这个函数不是真正的并发?(因为这个完成变量强加了一种序列化)
BR, & 斯里达尔
最佳答案
不开启LOCK_DEP没有区别。
它仅对锁定调试功能有用。
查看下面的内核代码,
47/*
48 * Lockdep needs to run a non-constant initializer for on-stack
49 * completions - so we use the _ONSTACK() variant for those that
50 * are on the kernel stack:
51 */
59#ifdef CONFIG_LOCKDEP
60# define DECLARE_COMPLETION_ONSTACK(work) \
61 struct completion work = COMPLETION_INITIALIZER_ONSTACK(work)
62#else
63# define DECLARE_COMPLETION_ONSTACK(work) DECLARE_COMPLETION(work)
64#endif
关于linux - Linux 内核中的 DECLARE_COMPLETION_ONSTACK 功能,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27205152/