Kracken Kracken - 1 year ago 139
Linux Question

Read/Write lock for linux kernel module

I'm trying to protect my

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)


Answer Source

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.


static DEFINE_RWLOCK(myrwlock);


rwlock_t myrwlock;
static int __init rwlock_init(void)

instead of

rwlock_t myrwlock = RW_LOCK_UNLOCKED;
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download