2 * This file is part of the SPL: Solaris Porting Layer.
4 * Copyright (c) 2008 Lawrence Livermore National Security, LLC.
5 * Produced at Lawrence Livermore National Laboratory
7 * Brian Behlendorf <behlendorf1@llnl.gov>,
8 * Herb Wartens <wartens2@llnl.gov>,
9 * Jim Garlick <garlick@llnl.gov>
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.
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
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.
34 #include <linux/module.h>
35 #include <linux/hardirq.h>
36 #include <sys/types.h>
39 #define MUTEX_DEFAULT 0
41 #define MUTEX_ADAPTIVE 2
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
51 #define KM_MAGIC 0x42424242
52 #define KM_POISON 0x84
59 struct task_struct
*km_owner
;
60 struct semaphore
*km_sem
;
63 struct list_head km_list
;
67 extern int mutex_spin_max
;
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]++)
75 #define MUTEX_STAT_INC(stats, stat)
78 int spl_mutex_init(void);
79 void spl_mutex_fini(void);
81 extern int __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
);
92 #define mutex_init(mp, name, type, ibc) \
94 /* May never fail or all subsequent mutex_* calls will ASSERT */\
96 while(__spl_mutex_init(mp, #mp, type, ibc)); \
98 while(__spl_mutex_init(mp, name, type, ibc)); \
100 #define mutex_destroy(mp) __spl_mutex_destroy(mp)
101 #define mutex_tryenter(mp) __mutex_tryenter(mp)
102 #define mutex_enter(mp) __mutex_enter(mp)
103 #define mutex_exit(mp) __mutex_exit(mp)
104 #define mutex_owned(mp) __mutex_owned(mp)
105 #define mutex_owner(mp) __spl_mutex_owner(mp)
106 #define MUTEX_HELD(mp) mutex_owned(mp)
112 #endif /* _SPL_MUTEX_H */