[英]Read/Write lock for linux kernel module
I'm trying to protect my list
with data using read/write locks, i found solution in this thread: What's the best linux kernel locking mechanism for a specific scenario 我试图通过使用读/写锁的数据保护我的
list
,我在此线程中找到了解决方案: 针对特定情况的最佳linux内核锁定机制是什么
But i can't find needed headers for this solution, seems it is outdated, error: 但我找不到此解决方案所需的标头,似乎已经过时,错误:
error: 'RW_LOCK_UNLOCKED' undeclared here (not in a function)
Using <linux/spinlock.h>
使用
<linux/spinlock.h>
RW_LOCK_UNLOCKED
has been deprecated for a long time and finally removed in Linux 2.6.39, so now, according to the documentation : RW_LOCK_UNLOCKED
已被弃用很长时间,并最终在Linux 2.6.39中删除,因此, 根据文档 ,现在:
For dynamic initialization, use spin_lock_init() or rwlock_init() as appropriate:
对于动态初始化,请适当使用spin_lock_init()或rwlock_init():
...
...
For static initialization, use DEFINE_SPINLOCK() / DEFINE_RWLOCK() or __SPIN_LOCK_UNLOCKED() / __RW_LOCK_UNLOCKED() as appropriate.
对于静态初始化,请根据需要使用DEFINE_SPINLOCK()/ DEFINE_RWLOCK()或__SPIN_LOCK_UNLOCKED()/ __RW_LOCK_UNLOCKED()。
Like 喜欢
static DEFINE_RWLOCK(myrwlock);
or 要么
rwlock_t myrwlock;
static int __init rwlock_init(void)
{
rwlock_init(&myrwlock);
}
instead of 代替
rwlock_t myrwlock = RW_LOCK_UNLOCKED;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.