Paraslash Audio Streaming | |
About News Download Documentation Development |
Sched and task structures and exported symbols from sched.c. More...
Data Structures | |
struct | sched |
Paraslash's scheduler. More... | |
struct | task_info |
Information that must be supplied by callers of task_register(). More... | |
Functions | |
struct task * | task_register (struct task_info *info, struct sched *s) |
Add a task to the scheduler task list. More... | |
int | schedule (struct sched *s) |
The core function of all paraslash programs. More... | |
void | sched_shutdown (struct sched *s) |
Deallocate all resources of all tasks of a scheduler instance. More... | |
char * | get_task_list (struct sched *s) |
Get the list of all registered tasks. More... | |
void | task_notify (struct task *t, int err) |
Set the notification value of a task. More... | |
void | task_notify_all (struct sched *s, int err) |
Set the notification value of all tasks of a scheduler instance. More... | |
int | task_get_notification (const struct task *t) |
Return the notification value of a task. More... | |
int | task_status (const struct task *t) |
Return the status value of a task. More... | |
int | task_reap (struct task **tptr) |
Obtain the error status of a task and deallocate its resources. More... | |
void | sched_min_delay (struct sched *s) |
Set the I/O timeout to the minimal possible value. More... | |
void | sched_request_timeout (struct timeval *to, struct sched *s) |
Impose an upper bound for the I/O timeout. More... | |
void | sched_request_timeout_ms (long unsigned ms, struct sched *s) |
Bound the I/O timeout to at most the given amount of milliseconds. More... | |
int | sched_request_barrier (struct timeval *barrier, struct sched *s) |
Bound the I/O timeout by an absolute time in the future. More... | |
int | sched_request_barrier_or_min_delay (struct timeval *barrier, struct sched *s) |
Bound the I/O timeout or request a minimal delay. More... | |
void | sched_monitor_readfd (int fd, struct sched *s) |
Instruct the scheduler to monitor an fd for readiness for reading. More... | |
void | sched_monitor_writefd (int fd, struct sched *s) |
Instruct the scheduler to monitor an fd for readiness for writing. More... | |
bool | sched_read_ok (int fd, const struct sched *s) |
Check whether there is data to read on the given fd. More... | |
bool | sched_write_ok (int fd, const struct sched *s) |
Check whether writing is possible (i.e., does not block). More... | |
Variables | |
const struct timeval * | now |
This is set by the scheduler at the beginning of its main loop. More... | |
Sched and task structures and exported symbols from sched.c.
Add a task to the scheduler task list.
info | Task information supplied by the caller. |
s | The scheduler instance. |
References alloc(), list_head::next, task_info::post_monitor, and sched::task_list.
Referenced by register_writer_node().
int schedule | ( | struct sched * | s | ) |
The core function of all paraslash programs.
s | Pointer to the scheduler struct. |
This function updates the global now pointer, calls all registered pre_monitor hooks which may set the timeout and add any file descriptors to the pollfd array. Next, it calls the poll function and makes the result available to the registered tasks by calling their post_monitor hook.
References clock_get_realtime(), sched::default_timeout, sched::num_pfds, sched::pidx, sched::pidx_array_len, sched::poll_function, sched::timeout, and xpoll().
void sched_shutdown | ( | struct sched * | s | ) |
Deallocate all resources of all tasks of a scheduler instance.
s | The scheduler instance. |
This should only be called after schedule() has returned.
References list_for_each_entry_safe, PARA_WARNING_LOG, sched::task_list, and TS_RUNNING.
char* get_task_list | ( | struct sched * | s | ) |
Get the list of all registered tasks.
s | The scheduler instance to get the task list from. |
Each entry of the list contains an identifier which is simply a hex number. The result is dynamically allocated and must be freed by the caller.
References list_for_each_entry_safe, make_message(), sched::task_list, TS_DEAD, and TS_RUNNING.
Referenced by server_get_tasks().
void task_notify | ( | struct task * | t, |
int | err | ||
) |
Set the notification value of a task.
t | The task to notify. |
err | A positive error code. |
Tasks which honor notifications are supposed to call task_get_notification() in their post_monitor function and act on the returned notification value.
If the scheduler detects during its pre_monitor loop that at least one task has been notified, the loop terminates, and the post_monitor methods of all taks are immediately called again.
The notification for a task is reset after the call to its post_monitor method.
References PARA_INFO_LOG, and para_strerror().
Referenced by task_notify_all().
void task_notify_all | ( | struct sched * | s, |
int | err | ||
) |
Set the notification value of all tasks of a scheduler instance.
s | The scheduler instance whose tasks should be notified. |
err | A positive error code. |
This simply iterates over all existing tasks of s and sets each task's notification value to -err
.
References list_for_each_entry, sched::task_list, and task_notify().
int task_get_notification | ( | const struct task * | t | ) |
Return the notification value of a task.
t | The task to get the notification value from. |
int task_status | ( | const struct task * | t | ) |
Return the status value of a task.
t | The task to get the status value from. |
References TS_DEAD, and TS_RUNNING.
int task_reap | ( | struct task ** | tptr | ) |
Obtain the error status of a task and deallocate its resources.
tptr | Identifies the task to reap. |
This function is similar to wait(2) in that it returns information about a terminated task which allows releasing the resources associated with the task. Until this function is called, the terminated task remains in a zombie state.
NULL
, or *tptr is NULL
, the function does nothing and returns zero. Otherwise, it is checked whether the task identified by tptr is still running. If it is, the function returns zero and again, no action is taken. Otherwise the (negative) error code of the terminated task is returned and *tptr is set to NULL
. The task will then be removed removed from the scheduler task list.References PARA_INFO_LOG, para_strerror(), and TS_DEAD.
void sched_min_delay | ( | struct sched * | s | ) |
Set the I/O timeout to the minimal possible value.
s | Pointer to the scheduler struct. |
This causes the next poll() call to return immediately.
References sched::timeout.
Referenced by check_wav_pre_monitor(), generic_filter_pre_monitor(), generic_recv_pre_monitor(), and sched_request_barrier_or_min_delay().
void sched_request_timeout | ( | struct timeval * | to, |
struct sched * | s | ||
) |
Impose an upper bound for the I/O timeout.
to | Maximal allowed timeout. |
s | Pointer to the scheduler struct. |
If the current I/O timeout is already smaller than to, this function does nothing. Otherwise the timeout is set to the given value.
References sched::timeout, and tv2ms().
Referenced by sched_request_barrier(), sched_request_barrier_or_min_delay(), and sched_request_timeout_ms().
void sched_request_timeout_ms | ( | long unsigned | ms, |
struct sched * | s | ||
) |
Bound the I/O timeout to at most the given amount of milliseconds.
ms | The maximal allowed timeout in milliseconds. |
s | Pointer to the scheduler struct. |
Like sched_request_timeout() this imposes an upper bound on the I/O timeout.
References ms2tv(), and sched_request_timeout().
int sched_request_barrier | ( | struct timeval * | barrier, |
struct sched * | s | ||
) |
Bound the I/O timeout by an absolute time in the future.
barrier | Defines the upper bound for the timeout. |
s | Pointer to the scheduler struct. |
References now, sched_request_timeout(), and tv_diff().
int sched_request_barrier_or_min_delay | ( | struct timeval * | barrier, |
struct sched * | s | ||
) |
Bound the I/O timeout or request a minimal delay.
barrier | Absolute time as in sched_request_barrier(). |
s | Pointer to the scheduler struct. |
References now, sched_min_delay(), sched_request_timeout(), and tv_diff().
void sched_monitor_readfd | ( | int | fd, |
struct sched * | s | ||
) |
Instruct the scheduler to monitor an fd for readiness for reading.
fd | The file descriptor. |
s | The scheduler. |
Referenced by signal_pre_monitor().
void sched_monitor_writefd | ( | int | fd, |
struct sched * | s | ||
) |
Instruct the scheduler to monitor an fd for readiness for writing.
fd | The file descriptor. |
s | The scheduler. |
bool sched_read_ok | ( | int | fd, |
const struct sched * | s | ||
) |
Check whether there is data to read on the given fd.
To be called from the ->post_monitor() method of a task.
fd | Should have been monitored with sched_monitor_readfd(). |
s | The scheduler instance. |
bool sched_write_ok | ( | int | fd, |
const struct sched * | s | ||
) |
Check whether writing is possible (i.e., does not block).
fd | Should have been monitored with sched_monitor_writefd(). |
s | The scheduler instance. |
|
extern |
This is set by the scheduler at the beginning of its main loop.
It may be used (read-only) from everywhere. As none of the functions called by the scheduler are allowed to block, this value should be accurate enough so that there is no need to call clock_gettime() directly.
Referenced by audiod_status_dump(), sched_request_barrier(), and sched_request_barrier_or_min_delay().