1c7046f76SMartin Matuska /* 2*4d846d26SWarner Losh * SPDX-License-Identifier: BSD-2-Clause 3c7046f76SMartin Matuska * 4c7046f76SMartin Matuska * Copyright (c) 2022 Rob Wing 5c7046f76SMartin Matuska * 6c7046f76SMartin Matuska * Redistribution and use in source and binary forms, with or without 7c7046f76SMartin Matuska * modification, are permitted provided that the following conditions 8c7046f76SMartin Matuska * are met: 9c7046f76SMartin Matuska * 1. Redistributions of source code must retain the above copyright 10c7046f76SMartin Matuska * notice, this list of conditions and the following disclaimer. 11c7046f76SMartin Matuska * 2. Redistributions in binary form must reproduce the above copyright 12c7046f76SMartin Matuska * notice, this list of conditions and the following disclaimer in the 13c7046f76SMartin Matuska * documentation and/or other materials provided with the distribution. 14c7046f76SMartin Matuska * 15c7046f76SMartin Matuska * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 16c7046f76SMartin Matuska * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 17c7046f76SMartin Matuska * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 18c7046f76SMartin Matuska * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 19c7046f76SMartin Matuska * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 20c7046f76SMartin Matuska * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 21c7046f76SMartin Matuska * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 22c7046f76SMartin Matuska * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 23c7046f76SMartin Matuska * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 24c7046f76SMartin Matuska * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 25c7046f76SMartin Matuska * SUCH DAMAGE. 26c7046f76SMartin Matuska */ 27c7046f76SMartin Matuska 28c7046f76SMartin Matuska #include <sys/param.h> 29c7046f76SMartin Matuska #include <sys/lock.h> 30c7046f76SMartin Matuska #include <sys/sx.h> 31c7046f76SMartin Matuska #include <sys/event.h> 32c7046f76SMartin Matuska 33c7046f76SMartin Matuska #include <sys/freebsd_event.h> 34c7046f76SMartin Matuska 35c7046f76SMartin Matuska static void 36c7046f76SMartin Matuska knlist_sx_xlock(void *arg) 37c7046f76SMartin Matuska { 38c7046f76SMartin Matuska 39c7046f76SMartin Matuska sx_xlock((struct sx *)arg); 40c7046f76SMartin Matuska } 41c7046f76SMartin Matuska 42c7046f76SMartin Matuska static void 43c7046f76SMartin Matuska knlist_sx_xunlock(void *arg) 44c7046f76SMartin Matuska { 45c7046f76SMartin Matuska 46c7046f76SMartin Matuska sx_xunlock((struct sx *)arg); 47c7046f76SMartin Matuska } 48c7046f76SMartin Matuska 49c7046f76SMartin Matuska static void 50c7046f76SMartin Matuska knlist_sx_assert_lock(void *arg, int what) 51c7046f76SMartin Matuska { 52c7046f76SMartin Matuska 53c7046f76SMartin Matuska if (what == LA_LOCKED) 54c7046f76SMartin Matuska sx_assert((struct sx *)arg, SX_LOCKED); 55c7046f76SMartin Matuska else 56c7046f76SMartin Matuska sx_assert((struct sx *)arg, SX_UNLOCKED); 57c7046f76SMartin Matuska } 58c7046f76SMartin Matuska 59c7046f76SMartin Matuska void 60c7046f76SMartin Matuska knlist_init_sx(struct knlist *knl, struct sx *lock) 61c7046f76SMartin Matuska { 62c7046f76SMartin Matuska knlist_init(knl, lock, knlist_sx_xlock, knlist_sx_xunlock, 63c7046f76SMartin Matuska knlist_sx_assert_lock); 64c7046f76SMartin Matuska } 65