2008-05-26 08:38:26 +04:00
|
|
|
/*
|
|
|
|
* This file is part of the SPL: Solaris Porting Layer.
|
|
|
|
*
|
|
|
|
* Copyright (c) 2008 Lawrence Livermore National Security, LLC.
|
|
|
|
* Produced at Lawrence Livermore National Laboratory
|
|
|
|
* Written by:
|
|
|
|
* Brian Behlendorf <behlendorf1@llnl.gov>,
|
|
|
|
* Herb Wartens <wartens2@llnl.gov>,
|
|
|
|
* Jim Garlick <garlick@llnl.gov>
|
|
|
|
* UCRL-CODE-235197
|
|
|
|
*
|
|
|
|
* This is free software; you can redistribute it and/or modify it
|
|
|
|
* under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This is distributed in the hope that it will be useful, but WITHOUT
|
|
|
|
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
|
|
|
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
|
|
|
* for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License along
|
|
|
|
* with this program; if not, write to the Free Software Foundation, Inc.,
|
|
|
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
|
|
|
*/
|
|
|
|
|
2008-02-28 03:52:31 +03:00
|
|
|
#ifndef _SPL_MUTEX_H
|
|
|
|
#define _SPL_MUTEX_H
|
2008-02-26 23:36:04 +03:00
|
|
|
|
|
|
|
#ifdef __cplusplus
|
|
|
|
extern "C" {
|
|
|
|
#endif
|
|
|
|
|
2008-02-27 22:09:51 +03:00
|
|
|
#include <linux/module.h>
|
2008-04-11 21:03:57 +04:00
|
|
|
#include <linux/hardirq.h>
|
2008-03-01 03:45:59 +03:00
|
|
|
#include <sys/types.h>
|
2008-05-06 00:18:49 +04:00
|
|
|
#include <sys/kmem.h>
|
2008-02-27 22:09:51 +03:00
|
|
|
|
2008-02-26 23:36:04 +03:00
|
|
|
#define MUTEX_DEFAULT 0
|
2008-05-06 00:18:49 +04:00
|
|
|
#define MUTEX_SPIN 1
|
|
|
|
#define MUTEX_ADAPTIVE 2
|
|
|
|
|
|
|
|
#define MUTEX_ENTER_TOTAL 0
|
|
|
|
#define MUTEX_ENTER_NOT_HELD 1
|
|
|
|
#define MUTEX_ENTER_SPIN 2
|
|
|
|
#define MUTEX_ENTER_SLEEP 3
|
|
|
|
#define MUTEX_TRYENTER_TOTAL 4
|
|
|
|
#define MUTEX_TRYENTER_NOT_HELD 5
|
|
|
|
#define MUTEX_STATS_SIZE 6
|
2008-02-26 23:36:04 +03:00
|
|
|
|
|
|
|
#define KM_MAGIC 0x42424242
|
|
|
|
#define KM_POISON 0x84
|
2008-02-27 22:09:51 +03:00
|
|
|
|
2008-02-26 23:36:04 +03:00
|
|
|
typedef struct {
|
2008-05-06 00:18:49 +04:00
|
|
|
int32_t km_magic;
|
|
|
|
int16_t km_type;
|
|
|
|
int16_t km_name_size;
|
2008-02-26 23:36:04 +03:00
|
|
|
char *km_name;
|
|
|
|
struct task_struct *km_owner;
|
2008-05-06 00:18:49 +04:00
|
|
|
struct semaphore *km_sem;
|
|
|
|
#ifdef DEBUG_MUTEX
|
|
|
|
int *km_stats;
|
|
|
|
struct list_head km_list;
|
|
|
|
#endif
|
2008-02-26 23:36:04 +03:00
|
|
|
} kmutex_t;
|
|
|
|
|
2008-05-06 00:18:49 +04:00
|
|
|
extern int mutex_spin_max;
|
2008-02-26 23:36:04 +03:00
|
|
|
|
2008-05-06 00:18:49 +04:00
|
|
|
#ifdef DEBUG_MUTEX
|
|
|
|
extern int mutex_stats[MUTEX_STATS_SIZE];
|
2008-05-07 21:58:22 +04:00
|
|
|
extern spinlock_t mutex_stats_lock;
|
2008-05-06 00:18:49 +04:00
|
|
|
extern struct list_head mutex_stats_list;
|
|
|
|
#define MUTEX_STAT_INC(stats, stat) ((stats)[stat]++)
|
|
|
|
#else
|
|
|
|
#define MUTEX_STAT_INC(stats, stat)
|
|
|
|
#endif
|
2008-04-16 00:53:36 +04:00
|
|
|
|
2008-05-06 00:18:49 +04:00
|
|
|
int spl_mutex_init(void);
|
|
|
|
void spl_mutex_fini(void);
|
2008-04-16 00:53:36 +04:00
|
|
|
|
2008-06-04 10:00:46 +04:00
|
|
|
extern int __spl_mutex_init(kmutex_t *mp, char *name, int type, void *ibc);
|
2008-05-06 00:18:49 +04:00
|
|
|
extern void __spl_mutex_destroy(kmutex_t *mp);
|
|
|
|
extern int __mutex_tryenter(kmutex_t *mp);
|
|
|
|
extern void __mutex_enter(kmutex_t *mp);
|
|
|
|
extern void __mutex_exit(kmutex_t *mp);
|
|
|
|
extern int __mutex_owned(kmutex_t *mp);
|
|
|
|
extern kthread_t *__spl_mutex_owner(kmutex_t *mp);
|
2008-02-26 23:36:04 +03:00
|
|
|
|
2008-05-06 00:18:49 +04:00
|
|
|
#undef mutex_init
|
|
|
|
#undef mutex_destroy
|
2008-04-16 00:53:36 +04:00
|
|
|
|
2008-05-06 00:18:49 +04:00
|
|
|
#define mutex_init(mp, name, type, ibc) \
|
|
|
|
({ \
|
2008-06-04 10:00:46 +04:00
|
|
|
/* May never fail or all subsequent mutex_* calls will ASSERT */\
|
2008-05-06 00:18:49 +04:00
|
|
|
if ((name) == NULL) \
|
2008-06-04 10:00:46 +04:00
|
|
|
while(__spl_mutex_init(mp, #mp, type, ibc)); \
|
2008-05-06 00:18:49 +04:00
|
|
|
else \
|
2008-06-04 10:00:46 +04:00
|
|
|
while(__spl_mutex_init(mp, name, type, ibc)); \
|
2008-05-06 00:18:49 +04:00
|
|
|
})
|
2008-05-07 03:00:49 +04:00
|
|
|
#define mutex_destroy(mp) __spl_mutex_destroy(mp)
|
2008-05-06 00:18:49 +04:00
|
|
|
#define mutex_tryenter(mp) __mutex_tryenter(mp)
|
|
|
|
#define mutex_enter(mp) __mutex_enter(mp)
|
|
|
|
#define mutex_exit(mp) __mutex_exit(mp)
|
|
|
|
#define mutex_owned(mp) __mutex_owned(mp)
|
|
|
|
#define mutex_owner(mp) __spl_mutex_owner(mp)
|
|
|
|
#define MUTEX_HELD(mp) mutex_owned(mp)
|
2008-02-26 23:36:04 +03:00
|
|
|
|
|
|
|
#ifdef __cplusplus
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2008-02-28 03:52:31 +03:00
|
|
|
#endif /* _SPL_MUTEX_H */
|