]>
Commit | Line | Data |
---|---|---|
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_MUTEX_H | |
28 | #define _SPL_MUTEX_H | |
29 | ||
30 | #ifdef __cplusplus | |
31 | extern "C" { | |
32 | #endif | |
33 | ||
34 | #include <linux/module.h> | |
35 | #include <linux/hardirq.h> | |
36 | #include <sys/types.h> | |
37 | #include <sys/kmem.h> | |
38 | ||
39 | #define MUTEX_DEFAULT 0 | |
40 | #define MUTEX_SPIN 1 | |
41 | #define MUTEX_ADAPTIVE 2 | |
42 | ||
43 | #define MUTEX_ENTER_TOTAL 0 | |
44 | #define MUTEX_ENTER_NOT_HELD 1 | |
45 | #define MUTEX_ENTER_SPIN 2 | |
46 | #define MUTEX_ENTER_SLEEP 3 | |
47 | #define MUTEX_TRYENTER_TOTAL 4 | |
48 | #define MUTEX_TRYENTER_NOT_HELD 5 | |
49 | #define MUTEX_STATS_SIZE 6 | |
50 | ||
51 | #define KM_MAGIC 0x42424242 | |
52 | #define KM_POISON 0x84 | |
53 | ||
54 | typedef struct { | |
55 | int32_t km_magic; | |
56 | int16_t km_type; | |
57 | int16_t km_name_size; | |
58 | char *km_name; | |
59 | struct task_struct *km_owner; | |
60 | struct semaphore *km_sem; | |
61 | #ifdef DEBUG_MUTEX | |
62 | int *km_stats; | |
63 | struct list_head km_list; | |
64 | #endif | |
65 | } kmutex_t; | |
66 | ||
67 | extern int mutex_spin_max; | |
68 | ||
69 | #ifdef DEBUG_MUTEX | |
70 | extern int mutex_stats[MUTEX_STATS_SIZE]; | |
71 | extern spinlock_t mutex_stats_lock; | |
72 | extern struct list_head mutex_stats_list; | |
73 | #define MUTEX_STAT_INC(stats, stat) ((stats)[stat]++) | |
74 | #else | |
75 | #define MUTEX_STAT_INC(stats, stat) | |
76 | #endif | |
77 | ||
78 | int spl_mutex_init(void); | |
79 | void spl_mutex_fini(void); | |
80 | ||
81 | extern void __spl_mutex_init(kmutex_t *mp, char *name, int type, void *ibc); | |
82 | extern void __spl_mutex_destroy(kmutex_t *mp); | |
83 | extern int __mutex_tryenter(kmutex_t *mp); | |
84 | extern void __mutex_enter(kmutex_t *mp); | |
85 | extern void __mutex_exit(kmutex_t *mp); | |
86 | extern int __mutex_owned(kmutex_t *mp); | |
87 | extern kthread_t *__spl_mutex_owner(kmutex_t *mp); | |
88 | ||
89 | #undef mutex_init | |
90 | #undef mutex_destroy | |
91 | ||
92 | #define mutex_init(mp, name, type, ibc) \ | |
93 | ({ \ | |
94 | if ((name) == NULL) \ | |
95 | __spl_mutex_init(mp, #mp, type, ibc); \ | |
96 | else \ | |
97 | __spl_mutex_init(mp, name, type, ibc); \ | |
98 | }) | |
99 | #define mutex_destroy(mp) __spl_mutex_destroy(mp) | |
100 | #define mutex_tryenter(mp) __mutex_tryenter(mp) | |
101 | #define mutex_enter(mp) __mutex_enter(mp) | |
102 | #define mutex_exit(mp) __mutex_exit(mp) | |
103 | #define mutex_owned(mp) __mutex_owned(mp) | |
104 | #define mutex_owner(mp) __spl_mutex_owner(mp) | |
105 | #define MUTEX_HELD(mp) mutex_owned(mp) | |
106 | ||
107 | #ifdef __cplusplus | |
108 | } | |
109 | #endif | |
110 | ||
111 | #endif /* _SPL_MUTEX_H */ |