1 /*-
2 * SPDX-License-Identifier: BSD-2-Clause-FreeBSD
3 *
4 * Copyright (c) 2008 Attilio Rao <attilio@FreeBSD.org>
5 * All rights reserved.
6 *
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
9 * are met:
10 * 1. Redistributions of source code must retain the above copyright
11 * notice(s), this list of conditions and the following disclaimer as
12 * the first lines of this file unmodified other than the possible
13 * addition of one or more copyright notices.
14 * 2. Redistributions in binary form must reproduce the above copyright
15 * notice(s), this list of conditions and the following disclaimer in the
16 * documentation and/or other materials provided with the distribution.
17 *
18 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER(S) ``AS IS'' AND ANY
19 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
20 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
21 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER(S) BE LIABLE FOR ANY
22 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
23 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
24 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
25 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
26 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
27 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
28 * DAMAGE.
29 */
30
31
32 // Modified to support the Haiku FAT driver.
33
34 #include "sys/param.h"
35 #include "sys/lockmgr.h"
36 #include "sys/mutex.h"
37 #include "sys/systm.h"
38
39
40 /*! @param flags LK_EXCLUSIVE or LK_SHARED by itself write- or read-locks the node, respectively.
41 LK_RELEASE in combination with LK_EXCLUSIVE or LK_SHARED write- or read-unlocks the node,
42 respectively.
43 @param ilk Ignored in the Haiku port.
44 */
45 void
lockmgr(struct lock * lk,u_int flags,struct mtx * ilk)46 lockmgr(struct lock* lk, u_int flags, struct mtx* ilk)
47 {
48 if ((flags & LK_RELEASE) != 0) {
49 if ((flags & LK_SHARED) != 0)
50 rw_lock_read_unlock(&lk->haikuRW);
51 else
52 rw_lock_write_unlock(&lk->haikuRW);
53 } else if ((flags & LK_EXCLUSIVE) != 0) {
54 rw_lock_write_lock(&lk->haikuRW);
55 } else if ((flags & LK_SHARED) != 0) {
56 rw_lock_read_lock(&lk->haikuRW);
57 } else {
58 panic("unrecognized lockmgr flag\n");
59 }
60
61 return;
62 }
63