source: rtems-libbsd/rtemsbsd/rtems/rtems-kernel-rwlock.c @ 3f23fcd

55-freebsd-126-freebsd-12
Last change on this file since 3f23fcd was 3f23fcd, checked in by Sebastian Huber <sebastian.huber@…>, on 11/16/17 at 07:15:37

LOCKING(9): Remove dead code (KDTRACE_HOOKS)

  • Property mode set to 100644
File size: 5.7 KB
Line 
1/**
2 * @file
3 *
4 * @ingroup rtems_bsd_rtems
5 *
6 * @brief TODO.
7 */
8
9/*
10 * Copyright (c) 2011 OPTI Medical.  All rights reserved.
11 *
12 *  OPTI Medical
13 *  235 Hembree Park Drive
14 *  Roswell, GA 30076
15 *  USA
16 *  <kevin.kirspel@optimedical.com>
17 *
18 * Copyright (c) 2013-2015 embedded brains GmbH.  All rights reserved.
19 *
20 *  embedded brains GmbH
21 *  Dornierstr. 4
22 *  82178 Puchheim
23 *  Germany
24 *  <rtems@embedded-brains.de>
25 *
26 * Redistribution and use in source and binary forms, with or without
27 * modification, are permitted provided that the following conditions
28 * are met:
29 * 1. Redistributions of source code must retain the above copyright
30 *    notice, this list of conditions and the following disclaimer.
31 * 2. Redistributions in binary form must reproduce the above copyright
32 *    notice, this list of conditions and the following disclaimer in the
33 *    documentation and/or other materials provided with the distribution.
34 *
35 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
36 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
37 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
38 * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
39 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
40 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
41 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
42 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
43 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
44 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
45 * SUCH DAMAGE.
46 */
47
48#include <machine/rtems-bsd-kernel-space.h>
49#include <machine/rtems-bsd-muteximpl.h>
50
51#include <sys/param.h>
52#include <sys/types.h>
53#include <sys/systm.h>
54#include <sys/lock.h>
55#include <sys/rwlock.h>
56
57#ifndef INVARIANTS
58#define _rw_assert(rw, what, file, line)
59#endif
60
61static void     assert_rw(const struct lock_object *lock, int what);
62static void     lock_rw(struct lock_object *lock, uintptr_t how);
63static uintptr_t unlock_rw(struct lock_object *lock);
64
65struct lock_class lock_class_rw = {
66        .lc_name = "rw",
67        .lc_flags = LC_SLEEPLOCK | LC_RECURSABLE | LC_UPGRADABLE,
68        .lc_assert = assert_rw,
69#ifdef DDB
70        .lc_ddb_show = db_show_rwlock,
71#endif
72        .lc_lock = lock_rw,
73        .lc_unlock = unlock_rw,
74};
75
76#define rw_wowner(rw) rtems_bsd_mutex_owner(&(rw)->mutex)
77
78#define rw_recursed(rw) rtems_bsd_mutex_recursed(&(rw)->mutex)
79
80void
81assert_rw(const struct lock_object *lock, int what)
82{
83
84        rw_assert((const struct rwlock *)lock, what);
85}
86
87void
88lock_rw(struct lock_object *lock, uintptr_t how)
89{
90
91        rw_wlock((struct rwlock *)lock);
92}
93
94uintptr_t
95unlock_rw(struct lock_object *lock)
96{
97
98        rw_unlock((struct rwlock *)lock);
99        return (0);
100}
101
102void
103rw_init_flags(struct rwlock *rw, const char *name, int opts)
104{
105        int flags;
106
107        flags = LO_UPGRADABLE;
108        if (opts & RW_RECURSE)
109                flags |= LO_RECURSABLE;
110
111        rtems_bsd_mutex_init(&rw->lock_object, &rw->mutex, &lock_class_rw,
112            name, NULL, flags);
113}
114
115void
116rw_destroy(struct rwlock *rw)
117{
118
119        rtems_bsd_mutex_destroy(&rw->lock_object, &rw->mutex);
120}
121
122void
123rw_sysinit(void *arg)
124{
125  struct rw_args *args = arg;
126
127  rw_init(args->ra_rw, args->ra_desc);
128}
129
130void
131rw_sysinit_flags(void *arg)
132{
133  struct rw_args_flags *args = arg;
134
135  rw_init_flags(args->ra_rw, args->ra_desc, args->ra_flags);
136}
137
138int
139rw_wowned(struct rwlock *rw)
140{
141        return (rtems_bsd_mutex_owned(&rw->mutex));
142}
143
144void
145_rw_wlock(struct rwlock *rw, const char *file, int line)
146{
147        rtems_bsd_mutex_lock(&rw->lock_object, &rw->mutex);
148}
149
150int
151_rw_try_wlock(struct rwlock *rw, const char *file, int line)
152{
153        return (rtems_bsd_mutex_trylock(&rw->lock_object, &rw->mutex));
154}
155
156void
157_rw_wunlock(struct rwlock *rw, const char *file, int line)
158{
159        rtems_bsd_mutex_unlock(&rw->mutex);
160}
161
162void
163_rw_rlock(struct rwlock *rw, const char *file, int line)
164{
165        rtems_bsd_mutex_lock(&rw->lock_object, &rw->mutex);
166}
167
168int
169_rw_try_rlock(struct rwlock *rw, const char *file, int line)
170{
171        return (rtems_bsd_mutex_trylock(&rw->lock_object, &rw->mutex));
172}
173
174void
175_rw_runlock(struct rwlock *rw, const char *file, int line)
176{
177        rtems_bsd_mutex_unlock(&rw->mutex);
178}
179
180int
181_rw_try_upgrade(struct rwlock *rw, const char *file, int line)
182{
183        return (1);
184}
185
186void
187_rw_downgrade(struct rwlock *rw, const char *file, int line)
188{
189        /* Nothing to do */
190}
191
192#ifdef INVARIANT_SUPPORT
193/*
194 * In the non-WITNESS case, rw_assert() can only detect that at least
195 * *some* thread owns an rlock, but it cannot guarantee that *this*
196 * thread owns an rlock.
197 */
198void
199_rw_assert(const struct rwlock *rw, int what, const char *file, int line)
200{
201        const char *name = rtems_bsd_mutex_name(&rw->mutex);
202
203        switch (what) {
204        case RA_LOCKED:
205        case RA_LOCKED | RA_RECURSED:
206        case RA_LOCKED | RA_NOTRECURSED:
207        case RA_RLOCKED:
208        case RA_RLOCKED | RA_RECURSED:
209        case RA_RLOCKED | RA_NOTRECURSED:
210        case RA_WLOCKED:
211        case RA_WLOCKED | RA_RECURSED:
212        case RA_WLOCKED | RA_NOTRECURSED:
213                if (rw_wowner(rw) != _Thread_Get_executing())
214                        panic("Lock %s not exclusively locked @ %s:%d\n",
215                            name, file, line);
216                if (rw_recursed(rw)) {
217                        if (what & RA_NOTRECURSED)
218                                panic("Lock %s recursed @ %s:%d\n", name, file,
219                                    line);
220                } else if (what & RA_RECURSED)
221                        panic("Lock %s not recursed @ %s:%d\n", name, file,
222                            line);
223                break;
224        case RA_UNLOCKED:
225#ifdef WITNESS
226                witness_assert(&rw->lock_object, what, file, line);
227#else
228                /*
229                 * If we hold a write lock fail.  We can't reliably check
230                 * to see if we hold a read lock or not.
231                 */
232                if (rw_wowner(rw) == _Thread_Get_executing())
233                        panic("Lock %s exclusively locked @ %s:%d\n", name,
234                            file, line);
235#endif
236                break;
237        default:
238                panic("Unknown rw lock assertion: %d @ %s:%d", what, file,
239                    line);
240        }
241}
242#endif /* INVARIANT_SUPPORT */
Note: See TracBrowser for help on using the repository browser.