lkmpg/examples/example_rwlock.c
Andy Shevchenko e62dff0df4 treewide: Clean up the headers
The rule of thumb is to include the headers we are the direct user of.
In particular, if we need an atomic API, we include <linux/atomic.h>.

On the other hand we should not use headers for no reason. In particular,
if we are not doing any IRQ job, why is the <linux/irq.h> included?

Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
2023-02-23 12:54:30 +02:00

56 lines
1010 B
C

/*
* example_rwlock.c
*/
#include <linux/kernel.h>
#include <linux/module.h>
#include <linux/rwlock.h>
static DEFINE_RWLOCK(myrwlock);
static void example_read_lock(void)
{
unsigned long flags;
read_lock_irqsave(&myrwlock, flags);
pr_info("Read Locked\n");
/* Read from something */
read_unlock_irqrestore(&myrwlock, flags);
pr_info("Read Unlocked\n");
}
static void example_write_lock(void)
{
unsigned long flags;
write_lock_irqsave(&myrwlock, flags);
pr_info("Write Locked\n");
/* Write to something */
write_unlock_irqrestore(&myrwlock, flags);
pr_info("Write Unlocked\n");
}
static int example_rwlock_init(void)
{
pr_info("example_rwlock started\n");
example_read_lock();
example_write_lock();
return 0;
}
static void example_rwlock_exit(void)
{
pr_info("example_rwlock exit\n");
}
module_init(example_rwlock_init);
module_exit(example_rwlock_exit);
MODULE_DESCRIPTION("Read/Write locks example");
MODULE_LICENSE("GPL");