|A sleep queue used to implement condition variables.|
|SLEEPQ_SLEEP||A sleep queue used to implement sleep(9), wakeup(9) and wakeup_one(9).|
|SLEEPQ_PAUSE||A sleep queue used to implement pause(9).|
There are currently two optional flag:
|The current thread is entering an interruptible sleep.|
|When thread is entering an interruptible sleep, do not stop it upon arrival of stop action, like SIGSTOP. Wake it up instead.|
A timeout on the sleep may be specified by calling sleepq_set_timeout after sleepq_add. The wchan parameter should be the same value from the preceding call to sleepq_add, and the sleep queue chain associated with wchan must have been locked by a prior call to sleepq_lock. The timo parameter should specify the timeout value in ticks.
argument instead of
It allows to specify relative or absolute wakeup time with higher resolution
in form of
.Vt sbintime_t . The parameter pr allows to specify wanted absolute event precision. The parameter flags allows to pass additional callout_reset_sbt flags.
Once the thread is ready to suspend, one of the wait functions is called to put the current thread to sleep until it is awakened and to context switch to another thread. The sleepq_wait function is used for non-interruptible sleeps that do not have a timeout. The sleepq_timedwait function is used for non-interruptible sleeps that have had a timeout set via sleepq_set_timeout. The sleepq_wait_sig function is used for interruptible sleeps that do not have a timeout. The sleepq_timedwait_sig function is used for interruptible sleeps that do have a timeout set. The wchan argument to all of the wait functions is the wait channel being slept on. The sleep queue chain associated with argument wchan needs to have been locked with a prior call to sleepq_lock. The pri argument is used to set the priority of the thread when it is awakened. If it is set to zero, the threads priority is left alone.
When the thread is resumed, the wait functions return a non-zero value if the thread was awakened due to an interrupt other than a signal or a timeout. If the sleep timed out, then EWOULDBLOCK is returned. If the sleep was interrupted by something other than a signal, then some other return value will be returned.
A sleeping thread is normally resumed by the sleepq_broadcast and sleepq_signal functions. The sleepq_signal function awakens the highest priority thread sleeping on a wait channel while sleepq_broadcast awakens all of the threads sleeping on a wait channel. The wchan argument specifics which wait channel to awaken. The flags argument must match the sleep queue type contained in the flags argument passed to sleepq_add by the threads sleeping on the wait channel. If the pri argument does not equal -1, then each thread that is awakened will have its priority raised to pri if it has a lower priority. The sleep queue chain associated with argument wchan must be locked by a prior call to sleepq_lock before calling any of these functions. The queue argument specifies the sub-queue, from which threads need to be woken up.
A thread in an interruptible sleep can be interrupted by another thread via the sleepq_abort function. The td argument specifies the thread to interrupt. An individual thread can also be awakened from sleeping on a specific wait channel via the sleepq_remove function. The td argument specifies the thread to awaken and the wchan argument specifies the wait channel to awaken it from. If the thread td is not blocked on the wait channel wchan then this function will not do anything, even if the thread is asleep on a different wait channel. This function should only be used if one of the other functions above is not sufficient. One possible use is waking up a specific thread from a widely shared sleep channel.
The sleepq_sleepcnt function offer a simple way to retrieve the number of threads sleeping for the specified queue, given a wchan.
The sleepq_type function returns the type of wchan associated to a sleepqueue.
The sleepq_abort, sleepq_broadcast, and sleepq_signal functions all return a boolean value. If the return value is true, then at least one thread was resumed that is currently swapped out. The caller is responsible for awakening the scheduler process so that the resumed thread will be swapped back in. This is done by calling the kick_proc0 function after releasing the sleep queue chain lock via a call to sleepq_release.
The sleep queue interface is currently used to implement the sleep(9) and condvar(9) interfaces. Almost all other code in the kernel should use one of those interfaces rather than manipulating sleep queues directly.