1 /*-
2 * SPDX-License-Identifier: BSD-2-Clause-FreeBSD
3 *
4 * Copyright (c) 2007 Attilio Rao <attilio@freebsd.org>
5 * Copyright (c) 2001 Jason Evans <jasone@freebsd.org>
6 * All rights reserved.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
10 * are met:
11 * 1. Redistributions of source code must retain the above copyright
12 * notice(s), this list of conditions and the following disclaimer as
13 * the first lines of this file unmodified other than the possible
14 * addition of one or more copyright notices.
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice(s), this list of conditions and the following disclaimer in the
17 * documentation and/or other materials provided with the distribution.
18 *
19 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER(S) ``AS IS'' AND ANY
20 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
21 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
22 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER(S) BE LIABLE FOR ANY
23 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
24 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
25 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
26 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
27 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
28 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
29 * DAMAGE.
30 *
31 * $FreeBSD: releng/12.2/sys/sys/sx.h 336230 2018-07-12 22:34:40Z mjg $
32 */
33
34 #ifndef _SYS_SX_H_
35 #define _SYS_SX_H_
36
37 #include <pthread.h>
38
39 #ifdef __cplusplus
40 #if __cplusplus
41 extern "C" {
42 #endif /* __cplusplus */
43 #endif /* __cplusplus */
44
45 /* Ref. usb_device.c */
46 #define sx pthread_mutex
47
48 #define sx_init(sx, des) (void)pthread_mutex_init(sx, 0)
49 #define sx_init_flags(sx,des,flag) (void)pthread_mutex_init(sx, 0)
50 #define sx_destroy(sx) (void)pthread_mutex_destroy(sx)
51 #define sx_xlock(sx) (void)pthread_mutex_lock(sx)
52 #define sx_xunlock(sx) (void)pthread_mutex_unlock(sx)
53
54 #define sx_assert(sx, flag) do { \
55 if(!(sx)) \
56 panic("share/exclusive assert at %s:%d", __FUNCTION__, __LINE__); \
57 } while (0)
58
sx_xlocked(struct sx * sx)59 static inline int sx_xlocked(struct sx* sx)
60 {
61 if (sx->owner == (void *)OsCurrTaskGet()) {
62 return (1);
63 }
64 return (0);
65 }
66
67 #ifdef __cplusplus
68 #if __cplusplus
69 }
70 #endif /* __cplusplus */
71 #endif /* __cplusplus */
72
73 #endif /* !_SYS_SX_H_ */
74