Mikulas Patocka | 62ac665 | 2012-09-26 07:46:43 +0200 | [diff] [blame] | 1 | #ifndef _LINUX_PERCPU_RWSEM_H |
| 2 | #define _LINUX_PERCPU_RWSEM_H |
| 3 | |
Oleg Nesterov | 9390ef0 | 2012-12-17 16:01:36 -0800 | [diff] [blame] | 4 | #include <linux/atomic.h> |
Oleg Nesterov | a1fd3e2 | 2012-12-17 16:01:32 -0800 | [diff] [blame] | 5 | #include <linux/rwsem.h> |
Mikulas Patocka | 62ac665 | 2012-09-26 07:46:43 +0200 | [diff] [blame] | 6 | #include <linux/percpu.h> |
Oleg Nesterov | a1fd3e2 | 2012-12-17 16:01:32 -0800 | [diff] [blame] | 7 | #include <linux/wait.h> |
Oleg Nesterov | 8ebe347 | 2012-12-17 16:01:38 -0800 | [diff] [blame] | 8 | #include <linux/lockdep.h> |
Mikulas Patocka | 62ac665 | 2012-09-26 07:46:43 +0200 | [diff] [blame] | 9 | |
| 10 | struct percpu_rw_semaphore { |
Oleg Nesterov | a1fd3e2 | 2012-12-17 16:01:32 -0800 | [diff] [blame] | 11 | unsigned int __percpu *fast_read_ctr; |
Oleg Nesterov | 9390ef0 | 2012-12-17 16:01:36 -0800 | [diff] [blame] | 12 | atomic_t write_ctr; |
Oleg Nesterov | a1fd3e2 | 2012-12-17 16:01:32 -0800 | [diff] [blame] | 13 | struct rw_semaphore rw_sem; |
| 14 | atomic_t slow_read_ctr; |
| 15 | wait_queue_head_t write_waitq; |
Mikulas Patocka | 62ac665 | 2012-09-26 07:46:43 +0200 | [diff] [blame] | 16 | }; |
| 17 | |
Oleg Nesterov | a1fd3e2 | 2012-12-17 16:01:32 -0800 | [diff] [blame] | 18 | extern void percpu_down_read(struct percpu_rw_semaphore *); |
| 19 | extern void percpu_up_read(struct percpu_rw_semaphore *); |
Mikulas Patocka | 5c1eabe | 2012-10-22 19:37:47 -0400 | [diff] [blame] | 20 | |
Oleg Nesterov | a1fd3e2 | 2012-12-17 16:01:32 -0800 | [diff] [blame] | 21 | extern void percpu_down_write(struct percpu_rw_semaphore *); |
| 22 | extern void percpu_up_write(struct percpu_rw_semaphore *); |
Mikulas Patocka | 62ac665 | 2012-09-26 07:46:43 +0200 | [diff] [blame] | 23 | |
Oleg Nesterov | 8ebe347 | 2012-12-17 16:01:38 -0800 | [diff] [blame] | 24 | extern int __percpu_init_rwsem(struct percpu_rw_semaphore *, |
| 25 | const char *, struct lock_class_key *); |
Oleg Nesterov | a1fd3e2 | 2012-12-17 16:01:32 -0800 | [diff] [blame] | 26 | extern void percpu_free_rwsem(struct percpu_rw_semaphore *); |
Mikulas Patocka | 62ac665 | 2012-09-26 07:46:43 +0200 | [diff] [blame] | 27 | |
Oleg Nesterov | 8ebe347 | 2012-12-17 16:01:38 -0800 | [diff] [blame] | 28 | #define percpu_init_rwsem(brw) \ |
| 29 | ({ \ |
| 30 | static struct lock_class_key rwsem_key; \ |
| 31 | __percpu_init_rwsem(brw, #brw, &rwsem_key); \ |
| 32 | }) |
| 33 | |
Mikulas Patocka | 62ac665 | 2012-09-26 07:46:43 +0200 | [diff] [blame] | 34 | #endif |