Kracken Kracken - 3 months ago 28
Linux Question

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

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>

Answer

RW_LOCK_UNLOCKED has been deprecated for a long time and finally removed in Linux 2.6.39, so now, 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.

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;
Comments