init_sleepqueues sleepq_abort sleepq_add sleepq_alloc sleepq_broadcast sleepq_calc_signal_retval sleepq_catch_signals sleepq_free sleepq_lock sleepq_lookup sleepq_release sleepq_remove sleepq_signal sleepq_set_timeout sleepq_timedwait sleepq_timedwait_sig sleepq_wait sleepq_wait_sig - manage the queues of sleeping threads
The
sleepq_alloc ();
function allocates an inactive sleep queue and is used to assign a
sleep queue to a thread during thread creation.
The
sleepq_free ();
function frees the resources associated with an inactive sleep queue and is
used to free a queue during thread destruction.
Active sleep queues are stored in a hash table hashed on the addresses pointed
to by wait channels.
Each bucket in the hash table contains a sleep queue chain.
A sleep queue chain contains a spin mutex and a list of sleep queues that hash
to that specific chain.
Active sleep queues are protected by their chain's spin mutex.
The
init_sleepqueues ();
function initializes the hash table of sleep queue chains.
The
sleepq_lock ();
function locks the sleep queue chain associated with wait channel
Fa wchan .
The
sleepq_lookup ();
returns a pointer to the currently active sleep queue for that wait
channel associated with
Fa wchan
or
NULL
if there is no active sleep queue associated with
argument
Fa wchan .
It requires the sleep queue chain associated with
Fa wchan
to have been locked by a prior call to
sleepq_lock (.);
The
sleepq_release ();
function unlocks the sleep queue chain associated with
wchan ();
and is primarily useful when aborting a pending sleep request before one of
the wait functions is called.
The
sleepq_add ();
function places the current thread on the sleep queue associated with the
wait channel
Fa wchan .
The sleep queue chain associated with argument
Fa wchan
must be locked by a prior call to
sleepq_lock ();
when this function is called.
If a lock is specified via the
Fa lock
argument, and if the kernel was compiled with
options INVARIANTS
then the sleep queue code will perform extra checks to ensure that
the lock is used by all threads sleeping on
Fa wchan .
The
Fa wmesg
parameter should be a short description of
Fa wchan .
The
Fa flags
parameter is a bitmask consisting of the type of sleep queue being slept on
and zero or more optional flags.
The
Fa queue
parameter specifies the sub-queue, in which the contending thread will be
inserted.
There are currently three types of sleep queues:
There is currently only one optional flag:
A timeout on the sleep may be specified by calling
sleepq_set_timeout ();
after
sleepq_add (.);
The
Fa wchan
parameter should be the same value from the preceding call to
sleepq_add (,);
and the sleep queue chain associated with
Fa wchan
must have been locked by a prior call to
sleepq_lock (.);
The
Fa timo
parameter should specify the timeout value in ticks.
The current thread may be marked interruptible by calling
sleepq_catch_signals ();
with
Fa wchan
set to the wait channel.
This function returns a signal number if there are any pending signals for
the current thread and 0 if there is not a pending signal.
The sleep queue chain associated with argument
Fa wchan
should have been locked by a prior call to
sleepq_lock (.);
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
Fa wchan
argument to all of the wait functions is the wait channel being slept
on.
The sleep queue chain associated with argument
Fa wchan
needs to have been locked with a prior call to
sleepq_lock (.);
The
Fa signal_caught
parameter to
sleepq_timedwait_sig ();
specifies if a previous call to
sleepq_catch_signals ();
found a pending signal.
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
Er EWOULDBLOCK
is returned.
If the sleep was interrupted by something other than a signal,
then some other return value will be returned.
If zero is returned after resuming from an interruptible sleep,
then
sleepq_calc_signal_retval ();
should be called to determine if the sleep was interrupted by a signal.
If so,
sleepq_calc_signal_retval ();
returns
Er ERESTART
if the interrupting signal is restartable and
Er EINTR
otherwise.
If the sleep was not interrupted by a signal,
sleepq_calc_signal_retval ();
will return 0.
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
Fa wchan
argument specifics which wait channel to awaken.
The
Fa flags
argument must match the sleep queue type contained in the
Fa flags
argument passed to
sleepq_add ();
by the threads sleeping on the wait channel.
If the
Fa pri
argument does not equal -1,
then each thread that is awakened will have its priority raised to
Fa pri
if it has a lower priority.
The sleep queue chain associated with argument
Fa wchan
must be locked by a prior call to
sleepq_lock ();
before calling any of these functions.
The
Fa 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
Fa 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
Fa td
argument specifies the thread to awaken and the
Fa wchan
argument specifies the wait channel to awaken it from.
If the thread
Fa td
is not blocked on the the wait channel
Fa 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 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.
Закладки на сайте Проследить за страницей |
Created 1996-2024 by Maxim Chirkov Добавить, Поддержать, Вебмастеру |