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-03-01 03:45:59 +03:00
|
|
|
#include <sys/rwlock.h>
|
2008-02-26 23:36:04 +03:00
|
|
|
|
2008-04-21 21:29:47 +04:00
|
|
|
#ifdef DEBUG_SUBSYSTEM
|
|
|
|
#undef DEBUG_SUBSYSTEM
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#define DEBUG_SUBSYSTEM S_RWLOCK
|
|
|
|
|
2008-05-07 03:00:49 +04:00
|
|
|
#ifdef CONFIG_RWSEM_GENERIC_SPINLOCK
|
2009-09-19 03:09:47 +04:00
|
|
|
|
|
|
|
/*
|
|
|
|
* From lib/rwsem-spinlock.c but modified such that the caller is
|
|
|
|
* responsible for acquiring and dropping the sem->wait_lock.
|
|
|
|
*/
|
2008-05-07 03:00:49 +04: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-19 03:09:47 +04:00
|
|
|
|
2008-05-07 03:00:49 +04:00
|
|
|
/* wake a single writer */
|
|
|
|
static struct rw_semaphore *
|
|
|
|
__rwsem_wake_one_writer_locked(struct rw_semaphore *sem)
|
|
|
|
{
|
2009-09-19 03:09:47 +04:00
|
|
|
struct rwsem_waiter *waiter;
|
|
|
|
struct task_struct *tsk;
|
2008-05-07 03:00:49 +04:00
|
|
|
|
2009-09-19 03:09:47 +04:00
|
|
|
sem->activity = -1;
|
2008-05-07 03:00:49 +04:00
|
|
|
|
2009-09-19 03:09:47 +04:00
|
|
|
waiter = list_entry(sem->wait_list.next, struct rwsem_waiter, list);
|
|
|
|
list_del(&waiter->list);
|
2008-05-07 03:00:49 +04:00
|
|
|
|
2009-09-19 03:09:47 +04:00
|
|
|
tsk = waiter->task;
|
|
|
|
smp_mb();
|
|
|
|
waiter->task = NULL;
|
|
|
|
wake_up_process(tsk);
|
|
|
|
put_task_struct(tsk);
|
|
|
|
return sem;
|
2008-05-07 03:00:49 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/* release a read lock on the semaphore */
|
2009-09-19 03:09:47 +04:00
|
|
|
void
|
2008-05-07 03:00:49 +04:00
|
|
|
__up_read_locked(struct rw_semaphore *sem)
|
|
|
|
{
|
2009-09-19 03:09:47 +04:00
|
|
|
if (--sem->activity == 0 && !list_empty(&sem->wait_list))
|
|
|
|
(void)__rwsem_wake_one_writer_locked(sem);
|
2008-05-07 03:00:49 +04:00
|
|
|
}
|
2009-09-19 03:09:47 +04:00
|
|
|
EXPORT_SYMBOL(__up_read_locked);
|
2008-05-07 03:00:49 +04:00
|
|
|
|
|
|
|
/* trylock for writing -- returns 1 if successful, 0 if contention */
|
|
|
|
int
|
2009-09-19 03:09:47 +04:00
|
|
|
__down_write_trylock_locked(struct rw_semaphore *sem)
|
2008-05-07 03:00:49 +04:00
|
|
|
{
|
2009-09-19 03:09:47 +04:00
|
|
|
int ret = 0;
|
2008-05-07 03:00:49 +04:00
|
|
|
|
2009-09-19 03:09:47 +04:00
|
|
|
if (sem->activity == 0 && list_empty(&sem->wait_list)) {
|
|
|
|
sem->activity = -1;
|
|
|
|
ret = 1;
|
|
|
|
}
|
2008-02-26 23:36:04 +03:00
|
|
|
|
2009-09-19 03:09:47 +04:00
|
|
|
return ret;
|
2008-02-26 23:36:04 +03:00
|
|
|
}
|
2009-09-19 03:09:47 +04:00
|
|
|
EXPORT_SYMBOL(__down_write_trylock_locked);
|
2008-04-08 03:54:34 +04:00
|
|
|
|
2008-03-07 02:42:37 +03:00
|
|
|
#endif
|
2009-09-26 01:14:35 +04:00
|
|
|
|
|
|
|
int spl_rw_init(void) { return 0; }
|
|
|
|
void spl_rw_fini(void) { }
|