1 /*- 2 * SPDX-License-Identifier: BSD-2-Clause 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 32 #ifndef _SYS_SX_H_ 33 #define _SYS_SX_H_ 34 35 #include <pthread.h> 36 37 #ifdef __cplusplus 38 #if __cplusplus 39 extern "C" { 40 #endif /* __cplusplus */ 41 #endif /* __cplusplus */ 42 43 /* Ref. usb_device.c */ 44 #define sx pthread_mutex 45 46 #define sx_init(sx, des) (void)pthread_mutex_init(sx, 0) 47 #define sx_init_flags(sx,des,flag) (void)pthread_mutex_init(sx, 0) 48 #define sx_destroy(sx) (void)pthread_mutex_destroy(sx) 49 #define sx_xlock(sx) (void)pthread_mutex_lock(sx) 50 #define sx_xunlock(sx) (void)pthread_mutex_unlock(sx) 51 52 #define sx_assert(sx, flag) do { \ 53 if(!(sx)) \ 54 panic("share/exclusive assert at %s:%d", __FUNCTION__, __LINE__); \ 55 } while (0) 56 57 static inline int sx_xlocked(struct sx* sx) 58 { 59 if (sx->owner == (void *)OsCurrTaskGet()) { 60 return (1); 61 } 62 return (0); 63 } 64 65 #ifdef __cplusplus 66 #if __cplusplus 67 } 68 #endif /* __cplusplus */ 69 #endif /* __cplusplus */ 70 71 #endif /* !_SYS_SX_H_ */ 72