]> git.proxmox.com Git - mirror_spl.git/blob - include/sys/rwlock.h
Go through and add a header with the proper UCRL number.
[mirror_spl.git] / include / sys / rwlock.h
1 /*
2 * This file is part of the SPL: Solaris Porting Layer.
3 *
4 * Copyright (c) 2008 Lawrence Livermore National Security, LLC.
5 * Produced at Lawrence Livermore National Laboratory
6 * Written by:
7 * Brian Behlendorf <behlendorf1@llnl.gov>,
8 * Herb Wartens <wartens2@llnl.gov>,
9 * Jim Garlick <garlick@llnl.gov>
10 * UCRL-CODE-235197
11 *
12 * This is free software; you can redistribute it and/or modify it
13 * under the terms of the GNU General Public License as published by
14 * the Free Software Foundation; either version 2 of the License, or
15 * (at your option) any later version.
16 *
17 * This is distributed in the hope that it will be useful, but WITHOUT
18 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
19 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
20 * for more details.
21 *
22 * You should have received a copy of the GNU General Public License along
23 * with this program; if not, write to the Free Software Foundation, Inc.,
24 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
25 */
26
27 #ifndef _SPL_RWLOCK_H
28 #define _SPL_RWLOCK_H
29
30 #include <linux/module.h>
31 #include <linux/slab.h>
32 #include <linux/rwsem.h>
33 #include <asm/current.h>
34 #include <sys/types.h>
35 #include <sys/kmem.h>
36
37 #ifdef __cplusplus
38 extern "C" {
39 #endif
40
41 typedef enum {
42 RW_DRIVER = 2, /* driver (DDI) rwlock */
43 RW_DEFAULT = 4 /* kernel default rwlock */
44 } krw_type_t;
45
46 typedef enum {
47 RW_WRITER,
48 RW_READER
49 } krw_t;
50
51
52 #define RW_MAGIC 0x3423645a
53 #define RW_POISON 0xa6
54
55 typedef struct {
56 int32_t rw_magic;
57 int32_t rw_name_size;
58 char *rw_name;
59 struct rw_semaphore rw_sem;
60 struct task_struct *rw_owner; /* holder of the write lock */
61 } krwlock_t;
62
63 extern void __rw_init(krwlock_t *rwlp, char *name, krw_type_t type, void *arg);
64 extern void __rw_destroy(krwlock_t *rwlp);
65 extern int __rw_tryenter(krwlock_t *rwlp, krw_t rw);
66 extern void __rw_enter(krwlock_t *rwlp, krw_t rw);
67 extern void __rw_exit(krwlock_t *rwlp);
68 extern void __rw_downgrade(krwlock_t *rwlp);
69 extern int __rw_tryupgrade(krwlock_t *rwlp);
70 extern kthread_t *__rw_owner(krwlock_t *rwlp);
71 extern int __rw_read_held(krwlock_t *rwlp);
72 extern int __rw_write_held(krwlock_t *rwlp);
73 extern int __rw_lock_held(krwlock_t *rwlp);
74
75 #define rw_init(rwlp, name, type, arg) \
76 ({ \
77 if ((name) == NULL) \
78 __rw_init(rwlp, #rwlp, type, arg); \
79 else \
80 __rw_init(rwlp, name, type, arg); \
81 })
82 #define rw_destroy(rwlp) __rw_destroy(rwlp)
83 #define rw_tryenter(rwlp, rw) __rw_tryenter(rwlp, rw)
84 #define rw_enter(rwlp, rw) __rw_enter(rwlp, rw)
85 #define rw_exit(rwlp) __rw_exit(rwlp)
86 #define rw_downgrade(rwlp) __rw_downgrade(rwlp)
87 #define rw_tryupgrade(rwlp) __rw_tryupgrade(rwlp)
88 #define rw_owner(rwlp) __rw_owner(rwlp)
89 #define RW_READ_HELD(rwlp) __rw_read_held(rwlp)
90 #define RW_WRITE_HELD(rwlp) __rw_write_held(rwlp)
91 #define RW_LOCK_HELD(rwlp) __rw_lock_held(rwlp)
92
93 #ifdef __cplusplus
94 }
95 #endif
96
97 #endif /* _SPL_RWLOCK_H */