gpt4 book ai didi

linux - linux内核模块的读/写锁

转载 作者:塔克拉玛干 更新时间:2023-11-03 02:06:44 29 4
gpt4 key购买 nike

我正在努力保护我的 list对于使用读/写锁的数据,我在这个线程中找到了解决方案: What's the best linux kernel locking mechanism for a specific scenario

但我找不到此解决方案所需的 header ,似乎已过时,错误:

error: ‘RW_LOCK_UNLOCKED’ undeclared here (not in a function)

使用 <linux/spinlock.h>

最佳答案

RW_LOCK_UNLOCKED 已弃用很长时间,最终在 Linux 2.6.39 中删除,所以现在,according to the documentation :

For dynamic initialization, use spin_lock_init() or rwlock_init() as appropriate:

...

For static initialization, use DEFINE_SPINLOCK() / DEFINE_RWLOCK() or __SPIN_LOCK_UNLOCKED() / __RW_LOCK_UNLOCKED() as appropriate.

喜欢

static DEFINE_RWLOCK(myrwlock);

rwlock_t myrwlock;
static int __init rwlock_init(void)
{
rwlock_init(&myrwlock);
}

代替

rwlock_t myrwlock = RW_LOCK_UNLOCKED;

关于linux - linux内核模块的读/写锁,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38880604/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com