4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License (the "License").
6 * You may not use this file except in compliance with the License.
7 *
8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 * or http://www.opensolaris.org/os/licensing.
10 * See the License for the specific language governing permissions
11 * and limitations under the License.
12 *
13 * When distributing Covered Code, include this CDDL HEADER in each
14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 * If applicable, add the following below this CDDL HEADER, with the
16 * fields enclosed by brackets "[]" replaced with your own identifying
17 * information: Portions Copyright [yyyy] [name of copyright owner]
18 *
19 * CDDL HEADER END
20 */
21 /*
22 * Copyright (c) 1991, 2010, Oracle and/or its affiliates. All rights reserved.
23 * Copyright 2013 Nexenta Systems, Inc. All rights reserved.
24 */
25
26 #ifndef _SYS_MUTEX_H
27 #define _SYS_MUTEX_H
28
29 #include <sys/synch.h> /* lwp_mutex_t */
30
31 #ifdef __cplusplus
32 extern "C" {
33 #endif
34
35 /*
36 * Public interface to mutual exclusion locks. See mutex(9F) for details.
37 *
38 * The basic mutex type is MUTEX_ADAPTIVE, which is expected to be used
39 * in almost all of the kernel. MUTEX_SPIN provides interrupt blocking
40 * and must be used in interrupt handlers above LOCK_LEVEL. The iblock
41 * cookie argument to mutex_init() encodes the interrupt level to block.
42 * The iblock cookie must be NULL for adaptive locks.
43 *
56 MUTEX_DRIVER = 4, /* driver (DDI) mutex */
57 MUTEX_DEFAULT = 6 /* kernel default mutex */
58 } kmutex_type_t;
59
60 struct _kmutex {
61 lwp_mutex_t m_lock;
62 void *m_owner;
63 };
64 typedef struct _kmutex kmutex_t;
65
66 #if defined(_KERNEL) || defined(_FAKE_KERNEL)
67 /* See the real sys/mutex.h */
68 typedef struct pad_mutex {
69 kmutex_t pad_mutex;
70 #ifdef _LP64
71 char pad_pad[64 - sizeof (kmutex_t)];
72 #endif
73 } pad_mutex_t;
74 #endif /* _KERNEL */
75
76 #define MUTEX_HELD(x) (mutex_owned(x))
77 #define MUTEX_NOT_HELD(x) (!mutex_owned(x) || panicstr)
78
79 /*
80 * We're simulating the kernel mutex API here, and the
81 * user-level has a different signature, so rename.
82 */
83 #define mutex_init kmutex_init
84 #define mutex_destroy kmutex_destroy
85
86 extern void kmutex_init(kmutex_t *, char *, kmutex_type_t, void *);
87 extern void kmutex_destroy(kmutex_t *);
88
89 extern void mutex_enter(kmutex_t *);
90 extern int mutex_tryenter(kmutex_t *);
91 extern void mutex_exit(kmutex_t *);
92 extern int mutex_owned(const kmutex_t *);
93
94 extern void *mutex_owner(const kmutex_t *);
95
96 #ifdef __cplusplus
97 }
98 #endif
99
100 #endif /* _SYS_MUTEX_H */
|
4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License (the "License").
6 * You may not use this file except in compliance with the License.
7 *
8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 * or http://www.opensolaris.org/os/licensing.
10 * See the License for the specific language governing permissions
11 * and limitations under the License.
12 *
13 * When distributing Covered Code, include this CDDL HEADER in each
14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 * If applicable, add the following below this CDDL HEADER, with the
16 * fields enclosed by brackets "[]" replaced with your own identifying
17 * information: Portions Copyright [yyyy] [name of copyright owner]
18 *
19 * CDDL HEADER END
20 */
21 /*
22 * Copyright (c) 1991, 2010, Oracle and/or its affiliates. All rights reserved.
23 * Copyright 2013 Nexenta Systems, Inc. All rights reserved.
24 * Copyright 2017 RackTop Systems.
25 */
26
27 #ifndef _SYS_MUTEX_H
28 #define _SYS_MUTEX_H
29
30 #include <sys/synch.h> /* lwp_mutex_t */
31
32 #ifdef __cplusplus
33 extern "C" {
34 #endif
35
36 /*
37 * Public interface to mutual exclusion locks. See mutex(9F) for details.
38 *
39 * The basic mutex type is MUTEX_ADAPTIVE, which is expected to be used
40 * in almost all of the kernel. MUTEX_SPIN provides interrupt blocking
41 * and must be used in interrupt handlers above LOCK_LEVEL. The iblock
42 * cookie argument to mutex_init() encodes the interrupt level to block.
43 * The iblock cookie must be NULL for adaptive locks.
44 *
57 MUTEX_DRIVER = 4, /* driver (DDI) mutex */
58 MUTEX_DEFAULT = 6 /* kernel default mutex */
59 } kmutex_type_t;
60
61 struct _kmutex {
62 lwp_mutex_t m_lock;
63 void *m_owner;
64 };
65 typedef struct _kmutex kmutex_t;
66
67 #if defined(_KERNEL) || defined(_FAKE_KERNEL)
68 /* See the real sys/mutex.h */
69 typedef struct pad_mutex {
70 kmutex_t pad_mutex;
71 #ifdef _LP64
72 char pad_pad[64 - sizeof (kmutex_t)];
73 #endif
74 } pad_mutex_t;
75 #endif /* _KERNEL */
76
77 extern char *volatile panicstr; /* panic string pointer */
78
79 #define MUTEX_HELD(x) (mutex_owned(x))
80 #define MUTEX_NOT_HELD(x) (!mutex_owned(x) || panicstr)
81
82 /*
83 * We're simulating the kernel mutex API here, and the
84 * user-level has a different signature, so rename.
85 */
86 #define mutex_init kmutex_init
87 #define mutex_destroy kmutex_destroy
88
89 /*
90 * We want to avoid binding against the versions of these
91 * functions in libc which causes bad things to happen.
92 */
93 #define mutex_enter kmutex_enter
94 #define mutex_exit kmutex_exit
95
96 extern void kmutex_init(kmutex_t *, char *, kmutex_type_t, void *);
97 extern void kmutex_destroy(kmutex_t *);
98
99 extern void kmutex_enter(kmutex_t *);
100 extern void kmutex_exit(kmutex_t *);
101
102 extern int mutex_tryenter(kmutex_t *);
103 extern int mutex_owned(const kmutex_t *);
104
105 extern void *mutex_owner(const kmutex_t *);
106
107 #ifdef __cplusplus
108 }
109 #endif
110
111 #endif /* _SYS_MUTEX_H */
|