source: rtems-libbsd/freebsd/sys/rmlock.h @ 459afb1

4.1155-freebsd-126-freebsd-12freebsd-9.3
Last change on this file since 459afb1 was 459afb1, checked in by Jennifer Averett <jennifer.averett@…>, on 04/16/12 at 14:10:35

Implemented a version of rmlock using rwlock.

  • Property mode set to 100644
File size: 4.8 KB
Line 
1/*-
2 * Copyright (c) 2007 Stephan Uphoff <ups@FreeBSD.org>
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright
9 *    notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 *    notice, this list of conditions and the following disclaimer in the
12 *    documentation and/or other materials provided with the distribution.
13 * 3. Neither the name of the author nor the names of any co-contributors
14 *    may be used to endorse or promote products derived from this software
15 *    without specific prior written permission.
16 *
17 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
18 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20 * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
21 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
23 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
24 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
26 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
27 * SUCH DAMAGE.
28 *
29 * $FreeBSD$
30 */
31
32#ifndef _SYS_RMLOCK_HH_
33#define _SYS_RMLOCK_HH_
34
35#include <freebsd/sys/mutex.h>
36#include <freebsd/sys/_lock.h>
37#include <freebsd/sys/_rmlock.h>
38
39#ifdef _KERNEL
40
41/*
42 * Flags passed to rm_init(9).
43 */
44#define RM_NOWITNESS    0x00000001
45#define RM_RECURSE      0x00000002
46
47#ifndef __rtems__
48void    rm_init(struct rmlock *rm, const char *name);
49void    rm_init_flags(struct rmlock *rm, const char *name, int opts);
50void    rm_destroy(struct rmlock *rm);
51int     rm_wowned(struct rmlock *rm);
52void    rm_sysinit(void *arg);
53void    rm_sysinit_flags(void *arg);
54
55void    _rm_wlock_debug(struct rmlock *rm, const char *file, int line);
56void    _rm_wunlock_debug(struct rmlock *rm, const char *file, int line);
57void    _rm_rlock_debug(struct rmlock *rm, struct rm_priotracker *tracker,
58            const char *file, int line);
59void    _rm_runlock_debug(struct rmlock *rm,  struct rm_priotracker *tracker,
60            const char *file, int line);
61
62void    _rm_wlock(struct rmlock *rm);
63void    _rm_wunlock(struct rmlock *rm);
64void    _rm_rlock(struct rmlock *rm, struct rm_priotracker *tracker);
65void    _rm_runlock(struct rmlock *rm,  struct rm_priotracker *tracker);
66
67/*
68 * Public interface for lock operations.
69 */
70#ifndef LOCK_DEBUG
71#error LOCK_DEBUG not defined, include <sys/lock.h> before <sys/rmlock.h>
72#endif
73
74#if LOCK_DEBUG > 0
75#define rm_wlock(rm)    _rm_wlock_debug((rm), LOCK_FILE, LOCK_LINE)
76#define rm_wunlock(rm)  _rm_wunlock_debug((rm), LOCK_FILE, LOCK_LINE)
77#define rm_rlock(rm,tracker)  \
78    _rm_rlock_debug((rm),(tracker), LOCK_FILE, LOCK_LINE )
79#define rm_runlock(rm,tracker)  \
80    _rm_runlock_debug((rm), (tracker), LOCK_FILE, LOCK_LINE )
81#else
82#define rm_wlock(rm)            _rm_wlock((rm))
83#define rm_wunlock(rm)          _rm_wunlock((rm))
84#define rm_rlock(rm,tracker)    _rm_rlock((rm),(tracker))
85#define rm_runlock(rm,tracker)  _rm_runlock((rm), (tracker))
86#endif
87
88#else /* __rtems__ */
89  #define rm_init(rm, name)                rw_init(rm, name)
90  #define rm_init_flags(rm, name, opts)    rw_init_flags(rm, name, opts)
91  #define rm_destroy(rm)                   rw_destroy(rm)
92  #define rm_wowned(rm)                    rw_wowned(rm)
93  #define rm_sysinit(arg)                  rw_sysinit(arg)
94  #define rm_sysinit_flags(arg)            rw_sysinit_flags(arg)
95
96  #define rm_wlock(rm)                     rw_wlock((rm))
97  #define rm_wunlock(rm)                   rw_wunlock((rm))
98  #define rm_rlock(rm,tracker)             rw_rlock((rm))
99  #define rm_runlock(rm,tracker)           rw_runlock((rm))
100#endif /* __rtems__ */
101
102
103
104struct rm_args {
105        struct rmlock   *ra_rm;
106        const char      *ra_desc;
107};
108
109struct rm_args_flags {
110        struct rmlock   *ra_rm;
111        const char      *ra_desc;
112        int             ra_opts;
113};
114
115#define RM_SYSINIT(name, rm, desc)                                      \
116        static struct rm_args name##_args = {                           \
117                (rm),                                                   \
118                (desc),                                                 \
119        };                                                              \
120        SYSINIT(name##_rm_sysinit, SI_SUB_LOCK, SI_ORDER_MIDDLE,        \
121            rm_sysinit, &name##_args);                                  \
122        SYSUNINIT(name##_rm_sysuninit, SI_SUB_LOCK, SI_ORDER_MIDDLE,    \
123            rm_destroy, (rm))
124
125
126#define RM_SYSINIT_FLAGS(name, rm, desc, opts)                          \
127        static struct rm_args name##_args = {                           \
128                (rm),                                                   \
129                (desc),                                                 \
130                (opts),                                                 \
131        };                                                              \
132        SYSINIT(name##_rm_sysinit, SI_SUB_LOCK, SI_ORDER_MIDDLE,        \
133            rm_sysinit_flags, &name##_args);                            \
134        SYSUNINIT(name##_rm_sysuninit, SI_SUB_LOCK, SI_ORDER_MIDDLE,    \
135            rm_destroy, (rm))
136
137#endif /* _KERNEL */
138#endif /* !_SYS_RMLOCK_HH_ */
Note: See TracBrowser for help on using the repository browser.