forked from sysprog21/lkmpg
-
Notifications
You must be signed in to change notification settings - Fork 0
/
example_rwlock.c
55 lines (40 loc) · 1 KB
/
example_rwlock.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
/*
* example_rwlock.c
*/
#include <linux/module.h>
#include <linux/printk.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 __init example_rwlock_init(void)
{
pr_info("example_rwlock started\n");
example_read_lock();
example_write_lock();
return 0;
}
static void __exit 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");