blob: 3e88c9a7d57f7fdaf5c1e8ee3194df6ae3677f13 [file] [log] [blame]
Mikulas Patocka62ac6652012-09-26 07:46:43 +02001#ifndef _LINUX_PERCPU_RWSEM_H
2#define _LINUX_PERCPU_RWSEM_H
3
Oleg Nesterov9390ef02012-12-17 16:01:36 -08004#include <linux/atomic.h>
Oleg Nesterova1fd3e22012-12-17 16:01:32 -08005#include <linux/rwsem.h>
Mikulas Patocka62ac6652012-09-26 07:46:43 +02006#include <linux/percpu.h>
Oleg Nesterova1fd3e22012-12-17 16:01:32 -08007#include <linux/wait.h>
Oleg Nesterov8ebe3472012-12-17 16:01:38 -08008#include <linux/lockdep.h>
Mikulas Patocka62ac6652012-09-26 07:46:43 +02009
10struct percpu_rw_semaphore {
Oleg Nesterova1fd3e22012-12-17 16:01:32 -080011 unsigned int __percpu *fast_read_ctr;
Oleg Nesterov9390ef02012-12-17 16:01:36 -080012 atomic_t write_ctr;
Oleg Nesterova1fd3e22012-12-17 16:01:32 -080013 struct rw_semaphore rw_sem;
14 atomic_t slow_read_ctr;
15 wait_queue_head_t write_waitq;
Mikulas Patocka62ac6652012-09-26 07:46:43 +020016};
17
Oleg Nesterova1fd3e22012-12-17 16:01:32 -080018extern void percpu_down_read(struct percpu_rw_semaphore *);
19extern void percpu_up_read(struct percpu_rw_semaphore *);
Mikulas Patocka5c1eabe2012-10-22 19:37:47 -040020
Oleg Nesterova1fd3e22012-12-17 16:01:32 -080021extern void percpu_down_write(struct percpu_rw_semaphore *);
22extern void percpu_up_write(struct percpu_rw_semaphore *);
Mikulas Patocka62ac6652012-09-26 07:46:43 +020023
Oleg Nesterov8ebe3472012-12-17 16:01:38 -080024extern int __percpu_init_rwsem(struct percpu_rw_semaphore *,
25 const char *, struct lock_class_key *);
Oleg Nesterova1fd3e22012-12-17 16:01:32 -080026extern void percpu_free_rwsem(struct percpu_rw_semaphore *);
Mikulas Patocka62ac6652012-09-26 07:46:43 +020027
Oleg Nesterov8ebe3472012-12-17 16:01:38 -080028#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 Patocka62ac6652012-09-26 07:46:43 +020034#endif