AquilaOS documentation
How it works, and its code
Loading...
Searching...
No Matches
waitq.h File Reference
#include <ds/list.h>

Go to the source code of this file.

Data Structures

struct  waitq

Functions

int waitq_sleep (struct waitq *waitq)
 Puts the current thread to sleep on a wait queue until it is woken up.
void waitq_sleep_unint (struct waitq *waitq)
 Puts the current thread to sleep on a wait queue until it is woken up, whatever signals come meanwhile.
void waitq_wakeup (struct waitq *waitq)
 Wakes up every thread sleeping on a wait queue, and every thread polling it.
void waitq_wakeup_nopoll (struct waitq *waitq)
 Wakes up every thread sleeping on a wait queue, but not the threads polling it.
void thread_wakeup (struct thread *thread)
 Wakes up one thread, if it is sleeping on a wait queue.
int poll_register (struct waitq *waitq)
 Registers a wait queue that the current thread, in select() or poll(), waits for: a wakeup of that queue also wakes the thread.
void poll_unregister (struct thread *thread)
 Removes every registration of a thread, when it stops waiting (it was woken up, or it is going away).

Function Documentation

◆ poll_register()

int poll_register ( struct waitq * queue)

Registers a wait queue that the current thread, in select() or poll(), waits for: a wakeup of that queue also wakes the thread.

Registering the same queue twice does nothing.

Parameters
queuethe wait queue, or NULL to be woken by any wakeup
Returns
0, or -ENOMEM if there was no memory for the registration

Definition at line 112 of file waitq.c.

References curthread, kmalloc(), poll_reg::next, poll_chain(), poll_register(), poll_regs, thread::poll_regs, poll_reg::queue, poll_reg::thread, and poll_reg::thread_next.

Referenced by fd_watch(), and poll_register().

◆ poll_unregister()

void poll_unregister ( struct thread * thread)

Removes every registration of a thread, when it stops waiting (it was woken up, or it is going away).

Parameters
threadthe thread whose registrations go

Definition at line 144 of file waitq.c.

References kfree(), poll_reg::next, poll_chain(), poll_regs, thread::poll_regs, poll_unregister(), poll_reg::queue, and poll_reg::thread_next.

Referenced by poll_unregister(), sys_poll(), sys_select(), and thread_kill().

◆ thread_wakeup()

void thread_wakeup ( struct thread * thread)

Wakes up one thread, if it is sleeping on a wait queue.

The other threads on that queue keep sleeping.

Parameters
threadthe thread to wake up

Definition at line 216 of file waitq.c.

References NULL, thread::run_link, sched_thread_wake(), thread_wakeup(), and thread::waitq.

Referenced by net_callout_set(), rx_queue(), sched_timer_tick(), signal_to(), and thread_wakeup().

◆ waitq_sleep()

int waitq_sleep ( struct waitq * waitq)

Puts the current thread to sleep on a wait queue until it is woken up.

A signal that the process doesn't block also ends the sleep (signal_to() wakes the thread). The system call should then return, so that the signal can be delivered. If a signal is already pending, the thread doesn't sleep at all.

A wakeup only means that something changed, so callers sleep in a loop and look again at what they wait for each time.

Parameters
waitqthe wait queue to sleep on
Returns
0 once woken up, or -ERESTARTSYS if a signal ended the sleep

Definition at line 50 of file waitq.c.

References curthread, ERESTARTSYS, ISLEEP, signal_interrupts(), sleep_on(), and waitq_sleep().

Referenced by pipefs_fifo_open(), posix_file_write(), pty_master_write(), pty_slave_write(), sched_wait(), socket_unix_accept(), socket_unix_connect(), socket_unix_recv(), socket_unix_send(), sys_sigsuspend(), sys_thread_join(), sys_waitpid(), tty_wait_start(), vfs_file_flock(), vt_kd_ioctl(), and waitq_sleep().

◆ waitq_sleep_unint()

void waitq_sleep_unint ( struct waitq * waitq)

Puts the current thread to sleep on a wait queue until it is woken up, whatever signals come meanwhile.

This is for waits that can't be abandoned halfway, such as a disk transfer or a page being read in.

Parameters
waitqthe wait queue to sleep on

Definition at line 67 of file waitq.c.

References sleep_on(), USLEEP, and waitq_sleep_unint().

Referenced by channel_acquire(), dma_transfer(), proc_threads_exec(), signal_stop(), and waitq_sleep_unint().

◆ waitq_wakeup()

◆ waitq_wakeup_nopoll()

void waitq_wakeup_nopoll ( struct waitq * waitq)

Wakes up every thread sleeping on a wait queue, but not the threads polling it.

This is for queues that no file descriptor waits through, such as a disk request's, and for the pollers' own queues.

Parameters
waitqthe wait queue (NULL does nothing)

Definition at line 196 of file waitq.c.

References list_entry, NULL, thread::run_link, sched_thread_wake(), waitq::threads, thread::waitq, and waitq_wakeup_nopoll().

Referenced by channel_release(), dma_irq(), poll_wake(), waitq_wakeup(), and waitq_wakeup_nopoll().