]> git.proxmox.com Git - mirror_spl-debian.git/blame - include/sys/mutex.h
Go through and add a header with the proper UCRL number.
[mirror_spl-debian.git] / include / sys / mutex.h
CommitLineData
715f6251 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
09b414e8 27#ifndef _SPL_MUTEX_H
28#define _SPL_MUTEX_H
f1ca4da6 29
30#ifdef __cplusplus
31extern "C" {
32#endif
33
f1b59d26 34#include <linux/module.h>
115aed0d 35#include <linux/hardirq.h>
f4b37741 36#include <sys/types.h>
9ab1ac14 37#include <sys/kmem.h>
f1b59d26 38
f1ca4da6 39#define MUTEX_DEFAULT 0
9ab1ac14 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
f1ca4da6 50
51#define KM_MAGIC 0x42424242
52#define KM_POISON 0x84
f1b59d26 53
f1ca4da6 54typedef struct {
9ab1ac14 55 int32_t km_magic;
56 int16_t km_type;
57 int16_t km_name_size;
f1ca4da6 58 char *km_name;
59 struct task_struct *km_owner;
9ab1ac14 60 struct semaphore *km_sem;
61#ifdef DEBUG_MUTEX
62 int *km_stats;
63 struct list_head km_list;
64#endif
f1ca4da6 65} kmutex_t;
66
9ab1ac14 67extern int mutex_spin_max;
f1ca4da6 68
9ab1ac14 69#ifdef DEBUG_MUTEX
70extern int mutex_stats[MUTEX_STATS_SIZE];
404992e3 71extern spinlock_t mutex_stats_lock;
9ab1ac14 72extern 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
d61e12af 77
9ab1ac14 78int spl_mutex_init(void);
79void spl_mutex_fini(void);
d61e12af 80
9ab1ac14 81extern void __spl_mutex_init(kmutex_t *mp, char *name, int type, void *ibc);
82extern void __spl_mutex_destroy(kmutex_t *mp);
83extern int __mutex_tryenter(kmutex_t *mp);
84extern void __mutex_enter(kmutex_t *mp);
85extern void __mutex_exit(kmutex_t *mp);
86extern int __mutex_owned(kmutex_t *mp);
87extern kthread_t *__spl_mutex_owner(kmutex_t *mp);
f1ca4da6 88
9ab1ac14 89#undef mutex_init
90#undef mutex_destroy
d61e12af 91
9ab1ac14 92#define mutex_init(mp, name, type, ibc) \
93({ \
9ab1ac14 94 if ((name) == NULL) \
95 __spl_mutex_init(mp, #mp, type, ibc); \
96 else \
97 __spl_mutex_init(mp, name, type, ibc); \
9ab1ac14 98})
e8b31e84 99#define mutex_destroy(mp) __spl_mutex_destroy(mp)
9ab1ac14 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)
f1ca4da6 106
107#ifdef __cplusplus
108}
109#endif
110
09b414e8 111#endif /* _SPL_MUTEX_H */