|
AquilaOS documentation
How it works, and its code
|
System calls that wait for any of several descriptors: select() (and pselect()) and poll(). More...
#include "syscalls.h"Go to the source code of this file.
Data Structures | |
| struct | fd_set |
Macros | |
| #define | FD_SETSIZE 64 |
| #define | NFDBITS (sizeof (fd_mask) * 8) |
| #define | _howmany(x, y) |
| #define | FD_BIT(set, i) |
| #define | FD_ADD(set, i) |
Typedefs | |
| typedef unsigned long | fd_mask |
Functions | |
| static struct file * | fd_peek (int fd) |
| Returns the open file a descriptor refers to, without holding it (as fd_file() does): it is only used until the call sleeps. | |
| static int | fd_ready (struct file *file, int write) |
| Returns whether file can be read (or written) without waiting. | |
| static int | fd_watch (struct file *file, int write) |
| Registers the wait queue that file's readers (or writers) sleep on, or NULL (any wakeup) if the file can't tell. | |
| static uint64_t | poll_deadline (int64_t ns) |
| Returns the deadline of a timeout of ns ns: 0 for none (ns < 0). | |
| long | sys_select (struct aquila_select_args *args) |
| Implements select() and pselect(): waits until a descriptor of the sets can be read or written, or the timeout passes, and says which can. | |
| long | sys_poll (struct pollfd *fds, nfds_t nfds, int timeout_ms) |
| Implements poll(): waits until one of the descriptors can be read or written, or the timeout passes, and says which can. | |
System calls that wait for any of several descriptors: select() (and pselect()) and poll().
Both look at each descriptor, registering the wait queue its readers (or writers) sleep on. If none is ready, the thread sleeps on its own queue (thread->poll_wait), which a wakeup of any registered queue also wakes, and then looks at them all again. See sys/waitq.c.
Definition in file sys_poll.c.
| #define _howmany | ( | x, | |
| y ) |
Definition at line 24 of file sys_poll.c.
| #define FD_ADD | ( | set, | |
| i ) |
Referenced by sys_select().
| #define FD_BIT | ( | set, | |
| i ) |
Referenced by sys_select().
| #define FD_SETSIZE 64 |
Definition at line 22 of file sys_poll.c.
Referenced by sys_select().
| #define NFDBITS (sizeof (fd_mask) * 8) |
Definition at line 23 of file sys_poll.c.
| typedef unsigned long fd_mask |
Definition at line 20 of file sys_poll.c.
|
static |
Returns the open file a descriptor refers to, without holding it (as fd_file() does): it is only used until the call sleeps.
Definition at line 15 of file sys_poll.c.
References curproc, fd_peek(), and proc_fd_file().
Referenced by fd_peek(), sys_poll(), and sys_select().
|
static |
Returns whether file can be read (or written) without waiting.
A file that can't tell counts as ready: the read or write reports the error.
Definition at line 33 of file sys_poll.c.
References fd_ready(), vfs_file_can_read(), and vfs_file_can_write().
Referenced by fd_ready(), sys_poll(), and sys_select().
|
static |
Registers the wait queue that file's readers (or writers) sleep on, or NULL (any wakeup) if the file can't tell.
Returns 0 or -ENOMEM.
Definition at line 41 of file sys_poll.c.
References fd_watch(), poll_register(), and vfs_file_wait_queue().
Referenced by fd_watch(), sys_poll(), and sys_select().
Returns the deadline of a timeout of ns ns: 0 for none (ns < 0).
A timeout of 0 means not to wait at all. A call restarted after a stop keeps the deadline it had.
Definition at line 49 of file sys_poll.c.
References arch_rtime_ns(), curthread, and poll_deadline().
Referenced by poll_deadline(), sys_poll(), and sys_select().
| long sys_poll | ( | struct pollfd * | fds, |
| nfds_t | nfds, | ||
| int | timeout_ms ) |
Implements poll(): waits until one of the descriptors can be read or written, or the timeout passes, and says which can.
| fds | the descriptors and the events wanted, in user memory; their revents are set |
| nfds | how many there are |
| timeout_ms | the timeout in ms, or -1 for none |
Definition at line 198 of file sys_poll.c.
References curthread, ERESTARTNOHAND, fd_peek(), fd_ready(), fd_watch(), FDS_COUNT, kfree(), kmalloc(), LOG_DEBUG, NULL, poll_deadline(), poll_unregister(), sched_wait(), and sys_poll().
Referenced by sys_poll().
| long sys_select | ( | struct aquila_select_args * | args | ) |
Implements select() and pselect(): waits until a descriptor of the sets can be read or written, or the timeout passes, and says which can.
Exceptional conditions are never reported.
| args | the arguments, in user memory: nfds, the read, write and except sets, the timeout, and pselect()'s signal mask |
Definition at line 68 of file sys_poll.c.
References curproc, curthread, ERESTARTNOHAND, FD_ADD, FD_BIT, fd_peek(), fd_ready(), FD_SETSIZE, fd_watch(), LOG_DEBUG, poll_deadline(), poll_unregister(), sched_wait(), SIG_UNMASKABLE, sys_select(), timeval::tv_sec, and timeval::tv_usec.
Referenced by sys_select().