2008-05-26 04:38:26 +00: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 00:52:31 +00:00
|
|
|
#ifndef _SPL_RWLOCK_H
|
2008-05-06 23:00:49 +00:00
|
|
|
#define _SPL_RWLOCK_H
|
2008-02-26 20:36:04 +00:00
|
|
|
|
2008-02-27 19:09:51 +00:00
|
|
|
#include <linux/module.h>
|
2008-02-26 20:36:04 +00:00
|
|
|
#include <linux/slab.h>
|
|
|
|
#include <linux/rwsem.h>
|
|
|
|
#include <asm/current.h>
|
2008-03-01 00:45:59 +00:00
|
|
|
#include <sys/types.h>
|
2008-05-06 23:00:49 +00:00
|
|
|
#include <sys/kmem.h>
|
2008-02-26 20:36:04 +00:00
|
|
|
|
2008-05-06 23:00:49 +00:00
|
|
|
#ifdef __cplusplus
|
2008-02-26 20:36:04 +00:00
|
|
|
extern "C" {
|
|
|
|
#endif
|
|
|
|
|
|
|
|
typedef enum {
|
|
|
|
RW_DRIVER = 2, /* driver (DDI) rwlock */
|
|
|
|
RW_DEFAULT = 4 /* kernel default rwlock */
|
|
|
|
} krw_type_t;
|
|
|
|
|
|
|
|
typedef enum {
|
|
|
|
RW_WRITER,
|
|
|
|
RW_READER
|
|
|
|
} krw_t;
|
|
|
|
|
|
|
|
|
|
|
|
#define RW_MAGIC 0x3423645a
|
|
|
|
#define RW_POISON 0xa6
|
|
|
|
|
|
|
|
typedef struct {
|
2008-05-06 23:00:49 +00:00
|
|
|
int32_t rw_magic;
|
|
|
|
int32_t rw_name_size;
|
2008-02-26 20:36:04 +00:00
|
|
|
char *rw_name;
|
|
|
|
struct rw_semaphore rw_sem;
|
2008-02-27 19:09:51 +00:00
|
|
|
struct task_struct *rw_owner; /* holder of the write lock */
|
2008-02-26 20:36:04 +00:00
|
|
|
} krwlock_t;
|
|
|
|
|
2008-05-06 23:00:49 +00:00
|
|
|
extern void __rw_init(krwlock_t *rwlp, char *name, krw_type_t type, void *arg);
|
|
|
|
extern void __rw_destroy(krwlock_t *rwlp);
|
|
|
|
extern int __rw_tryenter(krwlock_t *rwlp, krw_t rw);
|
|
|
|
extern void __rw_enter(krwlock_t *rwlp, krw_t rw);
|
|
|
|
extern void __rw_exit(krwlock_t *rwlp);
|
|
|
|
extern void __rw_downgrade(krwlock_t *rwlp);
|
|
|
|
extern int __rw_tryupgrade(krwlock_t *rwlp);
|
|
|
|
extern kthread_t *__rw_owner(krwlock_t *rwlp);
|
2008-03-06 23:42:37 +00:00
|
|
|
extern int __rw_read_held(krwlock_t *rwlp);
|
|
|
|
extern int __rw_write_held(krwlock_t *rwlp);
|
|
|
|
extern int __rw_lock_held(krwlock_t *rwlp);
|
|
|
|
|
2008-05-06 23:00:49 +00:00
|
|
|
#define rw_init(rwlp, name, type, arg) \
|
|
|
|
({ \
|
|
|
|
if ((name) == NULL) \
|
|
|
|
__rw_init(rwlp, #rwlp, type, arg); \
|
|
|
|
else \
|
|
|
|
__rw_init(rwlp, name, type, arg); \
|
|
|
|
})
|
|
|
|
#define rw_destroy(rwlp) __rw_destroy(rwlp)
|
|
|
|
#define rw_tryenter(rwlp, rw) __rw_tryenter(rwlp, rw)
|
|
|
|
#define rw_enter(rwlp, rw) __rw_enter(rwlp, rw)
|
|
|
|
#define rw_exit(rwlp) __rw_exit(rwlp)
|
|
|
|
#define rw_downgrade(rwlp) __rw_downgrade(rwlp)
|
|
|
|
#define rw_tryupgrade(rwlp) __rw_tryupgrade(rwlp)
|
|
|
|
#define rw_owner(rwlp) __rw_owner(rwlp)
|
|
|
|
#define RW_READ_HELD(rwlp) __rw_read_held(rwlp)
|
|
|
|
#define RW_WRITE_HELD(rwlp) __rw_write_held(rwlp)
|
|
|
|
#define RW_LOCK_HELD(rwlp) __rw_lock_held(rwlp)
|
|
|
|
|
|
|
|
#ifdef __cplusplus
|
2008-02-26 20:36:04 +00:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2008-05-06 23:00:49 +00:00
|
|
|
#endif /* _SPL_RWLOCK_H */
|