Linux Kernel  3.7.1
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
lglock.c
Go to the documentation of this file.
1 /* See include/linux/lglock.h for description */
2 #include <linux/module.h>
3 #include <linux/lglock.h>
4 #include <linux/cpu.h>
5 #include <linux/string.h>
6 
7 /*
8  * Note there is no uninit, so lglocks cannot be defined in
9  * modules (but it's fine to use them from there)
10  * Could be added though, just undo lg_lock_init
11  */
12 
13 void lg_lock_init(struct lglock *lg, char *name)
14 {
15  LOCKDEP_INIT_MAP(&lg->lock_dep_map, name, &lg->lock_key, 0);
16 }
18 
19 void lg_local_lock(struct lglock *lg)
20 {
22 
24  rwlock_acquire_read(&lg->lock_dep_map, 0, 0, _RET_IP_);
25  lock = this_cpu_ptr(lg->lock);
26  arch_spin_lock(lock);
27 }
29 
30 void lg_local_unlock(struct lglock *lg)
31 {
33 
34  rwlock_release(&lg->lock_dep_map, 1, _RET_IP_);
35  lock = this_cpu_ptr(lg->lock);
36  arch_spin_unlock(lock);
38 }
40 
41 void lg_local_lock_cpu(struct lglock *lg, int cpu)
42 {
44 
46  rwlock_acquire_read(&lg->lock_dep_map, 0, 0, _RET_IP_);
47  lock = per_cpu_ptr(lg->lock, cpu);
48  arch_spin_lock(lock);
49 }
51 
52 void lg_local_unlock_cpu(struct lglock *lg, int cpu)
53 {
55 
56  rwlock_release(&lg->lock_dep_map, 1, _RET_IP_);
57  lock = per_cpu_ptr(lg->lock, cpu);
58  arch_spin_unlock(lock);
60 }
62 
63 void lg_global_lock(struct lglock *lg)
64 {
65  int i;
66 
68  rwlock_acquire(&lg->lock_dep_map, 0, 0, _RET_IP_);
71  lock = per_cpu_ptr(lg->lock, i);
72  arch_spin_lock(lock);
73  }
74 }
76 
77 void lg_global_unlock(struct lglock *lg)
78 {
79  int i;
80 
81  rwlock_release(&lg->lock_dep_map, 1, _RET_IP_);
84  lock = per_cpu_ptr(lg->lock, i);
85  arch_spin_unlock(lock);
86  }
88 }