The Design and Implementation of the FreeBSD Operating System, Second Edition
Now available: The Design and Implementation of the FreeBSD Operating System (Second Edition)


[ source navigation ] [ diff markup ] [ identifier search ] [ freetext search ] [ file search ] [ list types ] [ track identifier ]

FreeBSD/Linux Kernel Cross Reference
sys/sys/sleepqueue.h

Version: -  FREEBSD  -  FREEBSD-13-STABLE  -  FREEBSD-13-0  -  FREEBSD-12-STABLE  -  FREEBSD-12-0  -  FREEBSD-11-STABLE  -  FREEBSD-11-0  -  FREEBSD-10-STABLE  -  FREEBSD-10-0  -  FREEBSD-9-STABLE  -  FREEBSD-9-0  -  FREEBSD-8-STABLE  -  FREEBSD-8-0  -  FREEBSD-7-STABLE  -  FREEBSD-7-0  -  FREEBSD-6-STABLE  -  FREEBSD-6-0  -  FREEBSD-5-STABLE  -  FREEBSD-5-0  -  FREEBSD-4-STABLE  -  FREEBSD-3-STABLE  -  FREEBSD22  -  l41  -  OPENBSD  -  linux-2.6  -  MK84  -  PLAN9  -  xnu-8792 
SearchContext: -  none  -  3  -  10 

    1 /*-
    2  * Copyright (c) 2004 John Baldwin <jhb@FreeBSD.org>
    3  * All rights reserved.
    4  *
    5  * Redistribution and use in source and binary forms, with or without
    6  * modification, are permitted provided that the following conditions
    7  * are met:
    8  * 1. Redistributions of source code must retain the above copyright
    9  *    notice, this list of conditions and the following disclaimer.
   10  * 2. Redistributions in binary form must reproduce the above copyright
   11  *    notice, this list of conditions and the following disclaimer in the
   12  *    documentation and/or other materials provided with the distribution.
   13  * 3. Neither the name of the author nor the names of any co-contributors
   14  *    may be used to endorse or promote products derived from this software
   15  *    without specific prior written permission.
   16  *
   17  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
   18  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
   19  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
   20  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
   21  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
   22  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
   23  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
   24  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
   25  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
   26  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   27  * SUCH DAMAGE.
   28  *
   29  * $FreeBSD: releng/9.2/sys/sys/sleepqueue.h 216421 2010-12-13 23:53:55Z mckusick $
   30  */
   31 
   32 #ifndef _SYS_SLEEPQUEUE_H_
   33 #define _SYS_SLEEPQUEUE_H_
   34 
   35 /*
   36  * Sleep queue interface.  Sleep/wakeup, condition variables, and sx
   37  * locks use a sleep queue for the queue of threads blocked on a sleep
   38  * channel.
   39  *
   40  * A thread calls sleepq_lock() to lock the sleep queue chain associated
   41  * with a given wait channel.  A thread can then call call sleepq_add() to
   42  * add themself onto a sleep queue and call one of the sleepq_wait()
   43  * functions to actually go to sleep.  If a thread needs to abort a sleep
   44  * operation it should call sleepq_release() to unlock the associated sleep
   45  * queue chain lock.  If the thread also needs to remove itself from a queue
   46  * it just enqueued itself on, it can use sleepq_remove() instead.
   47  *
   48  * If the thread only wishes to sleep for a limited amount of time, it can
   49  * call sleepq_set_timeout() after sleepq_add() to setup a timeout.  It
   50  * should then use one of the sleepq_timedwait() functions to block.
   51  *
   52  * If the thread wants the sleep to be interruptible by signals, it can
   53  * call sleepq_catch_signals() after sleepq_add().  It should then use
   54  * one of the sleepq_wait_sig() functions to block.  After the thread has
   55  * been resumed, it should call sleepq_calc_signal_retval() to determine
   56  * if it should return EINTR or ERESTART passing in the value returned from
   57  * the earlier call to sleepq_catch_signals().
   58  *
   59  * A thread is normally resumed from a sleep queue by either the
   60  * sleepq_signal() or sleepq_broadcast() functions.  Sleepq_signal() wakes
   61  * the thread with the highest priority that is sleeping on the specified
   62  * wait channel.  Sleepq_broadcast() wakes all threads that are sleeping
   63  * on the specified wait channel.  A thread sleeping in an interruptible
   64  * sleep can be interrupted by calling sleepq_abort().  A thread can also
   65  * be removed from a specified sleep queue using the sleepq_remove()
   66  * function.  Note that the sleep queue chain must first be locked via
   67  * sleepq_lock() before calling sleepq_abort(), sleepq_broadcast(), or
   68  * sleepq_signal().  These routines each return a boolean that will be true
   69  * if at least one swapped-out thread was resumed.  In that case, the caller
   70  * is responsible for waking up the swapper by calling kick_proc0() after
   71  * releasing the sleep queue chain lock.
   72  *
   73  * Each thread allocates a sleep queue at thread creation via sleepq_alloc()
   74  * and releases it at thread destruction via sleepq_free().  Note that
   75  * a sleep queue is not tied to a specific thread and that the sleep queue
   76  * released at thread destruction may not be the same sleep queue that the
   77  * thread allocated when it was created.
   78  *
   79  * XXX: Some other parts of the kernel such as ithread sleeping may end up
   80  * using this interface as well (death to TDI_IWAIT!)
   81  */
   82 
   83 struct lock_object;
   84 struct sleepqueue;
   85 struct thread;
   86 
   87 #ifdef _KERNEL
   88 
   89 #define SLEEPQ_TYPE             0x0ff           /* Mask of sleep queue types. */
   90 #define SLEEPQ_SLEEP            0x00            /* Used by sleep/wakeup. */
   91 #define SLEEPQ_CONDVAR          0x01            /* Used for a cv. */
   92 #define SLEEPQ_PAUSE            0x02            /* Used by pause. */
   93 #define SLEEPQ_SX               0x03            /* Used by an sx lock. */
   94 #define SLEEPQ_LK               0x04            /* Used by a lockmgr. */
   95 #define SLEEPQ_INTERRUPTIBLE    0x100           /* Sleep is interruptible. */
   96 #define SLEEPQ_STOP_ON_BDRY     0x200           /* Stop sleeping thread on
   97                                                    user mode boundary */
   98 
   99 void    init_sleepqueues(void);
  100 int     sleepq_abort(struct thread *td, int intrval);
  101 void    sleepq_add(void *wchan, struct lock_object *lock, const char *wmesg,
  102             int flags, int queue);
  103 struct sleepqueue *sleepq_alloc(void);
  104 int     sleepq_broadcast(void *wchan, int flags, int pri, int queue);
  105 void    sleepq_free(struct sleepqueue *sq);
  106 void    sleepq_lock(void *wchan);
  107 struct sleepqueue *sleepq_lookup(void *wchan);
  108 void    sleepq_release(void *wchan);
  109 void    sleepq_remove(struct thread *td, void *wchan);
  110 int     sleepq_signal(void *wchan, int flags, int pri, int queue);
  111 void    sleepq_set_timeout(void *wchan, int timo);
  112 u_int   sleepq_sleepcnt(void *wchan, int queue);
  113 int     sleepq_timedwait(void *wchan, int pri);
  114 int     sleepq_timedwait_sig(void *wchan, int pri);
  115 int     sleepq_type(void *wchan);
  116 void    sleepq_wait(void *wchan, int pri);
  117 int     sleepq_wait_sig(void *wchan, int pri);
  118 
  119 #endif  /* _KERNEL */
  120 #endif  /* !_SYS_SLEEPQUEUE_H_ */

Cache object: 49d47124c6363235a2c9068fc925bbb4


[ source navigation ] [ diff markup ] [ identifier search ] [ freetext search ] [ file search ] [ list types ] [ track identifier ]


This page is part of the FreeBSD/Linux Linux Kernel Cross-Reference, and was automatically generated using a modified version of the LXR engine.