1/* $NetBSD: sleepq.h,v 1.42 2023/10/15 10:30:00 riastradh Exp $ */ 2 3/*- 4 * Copyright (c) 2002, 2006, 2007, 2008, 2009, 2019, 2020, 2023 5 * The NetBSD Foundation, Inc. 6 * All rights reserved. 7 * 8 * This code is derived from software contributed to The NetBSD Foundation 9 * by Jason R. Thorpe and Andrew Doran. 10 * 11 * Redistribution and use in source and binary forms, with or without 12 * modification, are permitted provided that the following conditions 13 * are met: 14 * 1. Redistributions of source code must retain the above copyright 15 * notice, this list of conditions and the following disclaimer. 16 * 2. Redistributions in binary form must reproduce the above copyright 17 * notice, this list of conditions and the following disclaimer in the 18 * documentation and/or other materials provided with the distribution. 19 * 20 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS 21 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 22 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 23 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS 24 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 25 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 26 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 27 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 28 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 29 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 30 * POSSIBILITY OF SUCH DAMAGE. 31 */ 32 33#ifndef _SYS_SLEEPQ_H_ 34#define _SYS_SLEEPQ_H_ 35 36#include <sys/param.h> 37 38#include <sys/lwp.h> 39#include <sys/mutex.h> 40#include <sys/pool.h> 41#include <sys/queue.h> 42#include <sys/sched.h> 43#include <sys/wchan.h> 44 45struct syncobj; 46 47/* 48 * Generic sleep queues. 49 */ 50 51typedef struct sleepq sleepq_t; 52 53void sleepq_init(sleepq_t *); 54void sleepq_remove(sleepq_t *, lwp_t *, bool); 55int sleepq_enter(sleepq_t *, lwp_t *, kmutex_t *); 56void sleepq_enqueue(sleepq_t *, wchan_t, const char *, 57 const struct syncobj *, bool); 58void sleepq_transfer(lwp_t *, sleepq_t *, sleepq_t *, wchan_t, const char *, 59 const struct syncobj *, kmutex_t *, bool); 60void sleepq_uncatch(lwp_t *); 61void sleepq_unsleep(lwp_t *, bool); 62void sleepq_timeout(void *); 63void sleepq_wake(sleepq_t *, wchan_t, u_int, kmutex_t *); 64int sleepq_abort(kmutex_t *, int); 65void sleepq_changepri(lwp_t *, pri_t); 66void sleepq_lendpri(lwp_t *, pri_t); 67int sleepq_block(int, bool, const struct syncobj *, int); 68 69#ifdef _KERNEL 70 71#include <sys/kernel.h> 72 73typedef union { 74 kmutex_t lock; 75 uint8_t pad[COHERENCY_UNIT]; 76} sleepqlock_t; 77 78/* 79 * Return non-zero if it is unsafe to sleep. 80 * 81 * XXX This only exists because panic() is broken. 82 */ 83static __inline bool 84sleepq_dontsleep(lwp_t *l) 85{ 86 87 return cold || (doing_shutdown && (panicstr || CURCPU_IDLE_P())); 88} 89 90#endif /* _KERNEL */ 91 92#include <sys/sleeptab.h> 93 94#endif /* _SYS_SLEEPQ_H_ */ 95