|
AquilaOS documentation
How it works, and its code
|
Wait queues (see sys/waitq.h). More...
#include <core/system.h>#include <core/panic.h>#include <core/arch.h>#include <sys/proc.h>#include <sys/sched.h>#include <sys/signal.h>#include <sys/waitq.h>Go to the source code of this file.
Data Structures | |
| struct | poll_reg |
| One wait queue that one polling thread waits for. More... | |
Macros | |
| #define | POLL_HASH 64 |
Functions | |
| static void | sleep_on (struct waitq *waitq, state_t state) |
| Puts the current thread to sleep on waitq in state (ISLEEP or USLEEP), and returns once it has been woken up and has run again. | |
| 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. | |
| static struct poll_reg ** | poll_chain (struct waitq *queue) |
| Returns the hash chain that registrations of queue are on. | |
| 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. | |
| 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). | |
| static void | poll_wake (struct waitq *waitq) |
| Wakes up the threads polling waitq, and those polling any queue. | |
| 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. | |
Variables | |
| static struct poll_reg * | poll_hash [POLL_HASH] |
| static int | poll_regs |
Wait queues (see sys/waitq.h).
A thread that has to wait for something sleeps on the wait queue that belongs to it, and whatever makes it happen wakes the queue's threads up. select() and poll() wait for any of several queues at once.
Sleeping and waking up allocate nothing: a sleeping thread is linked into its wait queue through its own run_link, the same link that puts it on the ready list when it can run.
Definition in file waitq.c.
| #define POLL_HASH 64 |
Definition at line 93 of file waitq.c.
Referenced by poll_chain().
Returns the hash chain that registrations of queue are on.
Definition at line 99 of file waitq.c.
References poll_chain(), POLL_HASH, and poll_hash.
Referenced by poll_chain(), poll_register(), poll_unregister(), and poll_wake().
| 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.
| queue | the wait queue, or NULL to be woken by any wakeup |
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().
| 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).
| thread | the 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().
|
static |
Wakes up the threads polling waitq, and those polling any queue.
Definition at line 161 of file waitq.c.
References poll_reg::next, NULL, poll_chain(), poll_wake(), and waitq_wakeup_nopoll().
Referenced by poll_wake(), and waitq_wakeup().
Puts the current thread to sleep on waitq in state (ISLEEP or USLEEP), and returns once it has been woken up and has run again.
Definition at line 24 of file waitq.c.
References arch_sleep(), curthread, panic, RUNNABLE, sleep_on(), and waitq::threads.
Referenced by sleep_on(), waitq_sleep(), and waitq_sleep_unint().
| 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.
| thread | the 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().
| 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.
| waitq | the wait queue to sleep on |
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().
| 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.
| waitq | the 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().
| void waitq_wakeup | ( | struct waitq * | waitq | ) |
Wakes up every thread sleeping on a wait queue, and every thread polling it.
The threads become ready to run.
| waitq | the wait queue (NULL does nothing) |
Definition at line 178 of file waitq.c.
References poll_regs, poll_wake(), waitq_wakeup(), and waitq_wakeup_nopoll().
Referenced by inet_sock_deliver(), inet_sock_error(), lock_unlock(), pipefs_close(), pipefs_fifo_open(), posix_file_read(), posix_file_write(), proc_zombie_notify(), ps2mouse_handler(), ptm_read(), pts_read(), pty_free(), sched_thread_killed(), signal_notify_parent(), signal_to(), socket_inet_shut(), socket_unix_accept(), socket_unix_connect(), socket_unix_recv(), socket_unix_send(), socket_unix_shutdown(), sys_thread_exit(), tcp_wakeup(), tty_free(), tty_ioctl(), tty_master_write(), uart_receive_handler(), uart_transmit_handler(), unix_conn_wakeup(), vfs_file_flock(), vt_input_to(), vt_switch_now(), and waitq_wakeup().
| 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.
| waitq | the 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().
Definition at line 95 of file waitq.c.
Referenced by poll_chain().
|
static |
Definition at line 96 of file waitq.c.
Referenced by poll_register(), poll_unregister(), and waitq_wakeup().