2010-05-17 22:18:00 +00:00
|
|
|
/*****************************************************************************\
|
|
|
|
* Copyright (C) 2007-2010 Lawrence Livermore National Security, LLC.
|
|
|
|
* Copyright (C) 2007 The Regents of the University of California.
|
|
|
|
* Produced at Lawrence Livermore National Laboratory (cf, DISCLAIMER).
|
|
|
|
* Written by Brian Behlendorf <behlendorf1@llnl.gov>.
|
2008-05-26 04:38:26 +00:00
|
|
|
* UCRL-CODE-235197
|
|
|
|
*
|
2010-05-17 22:18:00 +00:00
|
|
|
* This file is part of the SPL, Solaris Porting Layer.
|
|
|
|
* For details, see <http://github.com/behlendorf/spl/>.
|
2008-05-26 04:38:26 +00:00
|
|
|
*
|
2010-05-17 22:18:00 +00:00
|
|
|
* The SPL 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.
|
|
|
|
*
|
|
|
|
* The SPL is distributed in the hope that it will be useful, but WITHOUT
|
2008-05-26 04:38:26 +00:00
|
|
|
* 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
|
2010-05-17 22:18:00 +00:00
|
|
|
* with the SPL. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*****************************************************************************
|
|
|
|
* Solaris Porting Layer (SPL) Reader/Writer Lock Implementation.
|
|
|
|
\*****************************************************************************/
|
2008-05-26 04:38:26 +00:00
|
|
|
|
2008-03-01 00:45:59 +00:00
|
|
|
#include <sys/rwlock.h>
|
2008-02-26 20:36:04 +00:00
|
|
|
|
2008-04-21 17:29:47 +00:00
|
|
|
#ifdef DEBUG_SUBSYSTEM
|
|
|
|
#undef DEBUG_SUBSYSTEM
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#define DEBUG_SUBSYSTEM S_RWLOCK
|
|
|
|
|
2008-05-06 23:00:49 +00:00
|
|
|
#ifdef CONFIG_RWSEM_GENERIC_SPINLOCK
|
2009-09-18 23:09:47 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* From lib/rwsem-spinlock.c but modified such that the caller is
|
|
|
|
* responsible for acquiring and dropping the sem->wait_lock.
|
|
|
|
*/
|
2008-05-06 23:00:49 +00:00
|
|
|
struct rwsem_waiter {
|
|
|
|
struct list_head list;
|
|
|
|
struct task_struct *task;
|
|
|
|
unsigned int flags;
|
|
|
|
#define RWSEM_WAITING_FOR_READ 0x00000001
|
|
|
|
#define RWSEM_WAITING_FOR_WRITE 0x00000002
|
|
|
|
};
|
2009-09-18 23:09:47 +00:00
|
|
|
|
2008-05-06 23:00:49 +00:00
|
|
|
/* wake a single writer */
|
|
|
|
static struct rw_semaphore *
|
|
|
|
__rwsem_wake_one_writer_locked(struct rw_semaphore *sem)
|
|
|
|
{
|
2009-09-18 23:09:47 +00:00
|
|
|
struct rwsem_waiter *waiter;
|
|
|
|
struct task_struct *tsk;
|
2008-05-06 23:00:49 +00:00
|
|
|
|
2009-09-18 23:09:47 +00:00
|
|
|
sem->activity = -1;
|
2008-05-06 23:00:49 +00:00
|
|
|
|
2009-09-18 23:09:47 +00:00
|
|
|
waiter = list_entry(sem->wait_list.next, struct rwsem_waiter, list);
|
|
|
|
list_del(&waiter->list);
|
2008-05-06 23:00:49 +00:00
|
|
|
|
2009-09-18 23:09:47 +00:00
|
|
|
tsk = waiter->task;
|
|
|
|
smp_mb();
|
|
|
|
waiter->task = NULL;
|
|
|
|
wake_up_process(tsk);
|
|
|
|
put_task_struct(tsk);
|
|
|
|
return sem;
|
2008-05-06 23:00:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* release a read lock on the semaphore */
|
2009-09-18 23:09:47 +00:00
|
|
|
void
|
2008-05-06 23:00:49 +00:00
|
|
|
__up_read_locked(struct rw_semaphore *sem)
|
|
|
|
{
|
2009-09-18 23:09:47 +00:00
|
|
|
if (--sem->activity == 0 && !list_empty(&sem->wait_list))
|
|
|
|
(void)__rwsem_wake_one_writer_locked(sem);
|
2008-05-06 23:00:49 +00:00
|
|
|
}
|
2009-09-18 23:09:47 +00:00
|
|
|
EXPORT_SYMBOL(__up_read_locked);
|
2008-05-06 23:00:49 +00:00
|
|
|
|
|
|
|
/* trylock for writing -- returns 1 if successful, 0 if contention */
|
|
|
|
int
|
2009-09-18 23:09:47 +00:00
|
|
|
__down_write_trylock_locked(struct rw_semaphore *sem)
|
2008-05-06 23:00:49 +00:00
|
|
|
{
|
2009-09-18 23:09:47 +00:00
|
|
|
int ret = 0;
|
2008-05-06 23:00:49 +00:00
|
|
|
|
2009-09-18 23:09:47 +00:00
|
|
|
if (sem->activity == 0 && list_empty(&sem->wait_list)) {
|
|
|
|
sem->activity = -1;
|
|
|
|
ret = 1;
|
|
|
|
}
|
2008-02-26 20:36:04 +00:00
|
|
|
|
2009-09-18 23:09:47 +00:00
|
|
|
return ret;
|
2008-02-26 20:36:04 +00:00
|
|
|
}
|
2009-09-18 23:09:47 +00:00
|
|
|
EXPORT_SYMBOL(__down_write_trylock_locked);
|
2008-04-07 23:54:34 +00:00
|
|
|
|
2008-03-06 23:42:37 +00:00
|
|
|
#endif
|
2009-09-25 21:14:35 +00:00
|
|
|
|
|
|
|
int spl_rw_init(void) { return 0; }
|
|
|
|
void spl_rw_fini(void) { }
|