]>
Commit | Line | Data |
---|---|---|
716154c5 BB |
1 | /*****************************************************************************\ |
2 | * Copyright (C) 2007-2010 Lawrence Livermore National Security, LLC. | |
3 | * Copyright (C) 2007 The Regents of the University of California. | |
4 | * Produced at Lawrence Livermore National Laboratory (cf, DISCLAIMER). | |
5 | * Written by Brian Behlendorf <behlendorf1@llnl.gov>. | |
715f6251 BB |
6 | * UCRL-CODE-235197 |
7 | * | |
716154c5 | 8 | * This file is part of the SPL, Solaris Porting Layer. |
3d6af2dd | 9 | * For details, see <http://zfsonlinux.org/>. |
715f6251 | 10 | * |
716154c5 BB |
11 | * The SPL is free software; you can redistribute it and/or modify it |
12 | * under the terms of the GNU General Public License as published by the | |
13 | * Free Software Foundation; either version 2 of the License, or (at your | |
14 | * option) any later version. | |
15 | * | |
16 | * The SPL is distributed in the hope that it will be useful, but WITHOUT | |
715f6251 BB |
17 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
18 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | |
19 | * for more details. | |
20 | * | |
21 | * You should have received a copy of the GNU General Public License along | |
716154c5 BB |
22 | * with the SPL. If not, see <http://www.gnu.org/licenses/>. |
23 | ***************************************************************************** | |
24 | * Solaris Porting Layer (SPL) Reader/Writer Lock Implementation. | |
25 | \*****************************************************************************/ | |
715f6251 | 26 | |
f4b37741 | 27 | #include <sys/rwlock.h> |
f1ca4da6 | 28 | |
937879f1 BB |
29 | #ifdef DEBUG_SUBSYSTEM |
30 | #undef DEBUG_SUBSYSTEM | |
31 | #endif | |
32 | ||
33 | #define DEBUG_SUBSYSTEM S_RWLOCK | |
34 | ||
e8b31e84 | 35 | #ifdef CONFIG_RWSEM_GENERIC_SPINLOCK |
e811949a BB |
36 | |
37 | /* | |
38 | * From lib/rwsem-spinlock.c but modified such that the caller is | |
39 | * responsible for acquiring and dropping the sem->wait_lock. | |
40 | */ | |
e8b31e84 BB |
41 | struct rwsem_waiter { |
42 | struct list_head list; | |
43 | struct task_struct *task; | |
44 | unsigned int flags; | |
45 | #define RWSEM_WAITING_FOR_READ 0x00000001 | |
46 | #define RWSEM_WAITING_FOR_WRITE 0x00000002 | |
47 | }; | |
e811949a | 48 | |
e8b31e84 BB |
49 | /* wake a single writer */ |
50 | static struct rw_semaphore * | |
51 | __rwsem_wake_one_writer_locked(struct rw_semaphore *sem) | |
52 | { | |
e811949a BB |
53 | struct rwsem_waiter *waiter; |
54 | struct task_struct *tsk; | |
e8b31e84 | 55 | |
e811949a | 56 | sem->activity = -1; |
e8b31e84 | 57 | |
e811949a BB |
58 | waiter = list_entry(sem->wait_list.next, struct rwsem_waiter, list); |
59 | list_del(&waiter->list); | |
e8b31e84 | 60 | |
e811949a BB |
61 | tsk = waiter->task; |
62 | smp_mb(); | |
63 | waiter->task = NULL; | |
64 | wake_up_process(tsk); | |
65 | put_task_struct(tsk); | |
66 | return sem; | |
e8b31e84 BB |
67 | } |
68 | ||
69 | /* release a read lock on the semaphore */ | |
e811949a | 70 | void |
e8b31e84 BB |
71 | __up_read_locked(struct rw_semaphore *sem) |
72 | { | |
e811949a BB |
73 | if (--sem->activity == 0 && !list_empty(&sem->wait_list)) |
74 | (void)__rwsem_wake_one_writer_locked(sem); | |
e8b31e84 | 75 | } |
e811949a | 76 | EXPORT_SYMBOL(__up_read_locked); |
e8b31e84 BB |
77 | |
78 | /* trylock for writing -- returns 1 if successful, 0 if contention */ | |
e8b31e84 | 79 | int |
e811949a | 80 | __down_write_trylock_locked(struct rw_semaphore *sem) |
e8b31e84 | 81 | { |
e811949a | 82 | int ret = 0; |
e8b31e84 | 83 | |
e811949a BB |
84 | if (sem->activity == 0 && list_empty(&sem->wait_list)) { |
85 | sem->activity = -1; | |
86 | ret = 1; | |
87 | } | |
f1ca4da6 | 88 | |
e811949a | 89 | return ret; |
f1ca4da6 | 90 | } |
e811949a | 91 | EXPORT_SYMBOL(__down_write_trylock_locked); |
79f92663 | 92 | |
ed61a7d0 | 93 | #endif |
d28db80f BB |
94 | |
95 | int spl_rw_init(void) { return 0; } | |
96 | void spl_rw_fini(void) { } |