systemd/man/sd_event_add_time.3
2015-02-17 11:22:16 +01:00

141 lines
6.3 KiB
Groff

'\" t
.TH "SD_EVENT_ADD_TIME" "3" "" "systemd 219" "sd_event_add_time"
.\" -----------------------------------------------------------------
.\" * Define some portability stuff
.\" -----------------------------------------------------------------
.\" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
.\" http://bugs.debian.org/507673
.\" http://lists.gnu.org/archive/html/groff/2009-02/msg00013.html
.\" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
.ie \n(.g .ds Aq \(aq
.el .ds Aq '
.\" -----------------------------------------------------------------
.\" * set default formatting
.\" -----------------------------------------------------------------
.\" disable hyphenation
.nh
.\" disable justification (adjust text to left margin only)
.ad l
.\" -----------------------------------------------------------------
.\" * MAIN CONTENT STARTS HERE *
.\" -----------------------------------------------------------------
.SH "NAME"
sd_event_add_time, sd_event_source_get_time, sd_event_source_set_time, sd_event_source_get_time_accuracy, sd_event_source_set_time_accuracy, sd_event_source_get_time_clock \- Add a timer event source to an event loop
.SH "SYNOPSIS"
.sp
.ft B
.nf
#include <systemd/sd\-bus\&.h>
.fi
.ft
.HP \w'int\ sd_event_add_time('u
.BI "int sd_event_add_time(sd_event\ *" "event" ", sd_event_source\ **" "source" ", clockid_t\ " "clock" ", uint64_t\ " "usec" ", uint64_t\ " "accuracy" ", sd_event_time_handler_t\ " "handler" ", void\ *" "userdata" ");"
.HP \w'typedef\ int\ (*sd_event_time_handler_t)('u
.BI "typedef int (*sd_event_time_handler_t)(sd_event_source\ *" "s" ", uint64_t\ " "usec" ", void\ *" "userdata" ");"
.HP \w'int\ sd_event_source_get_time('u
.BI "int sd_event_source_get_time(sd_event_source\ *" "source" ", usec_t\ *" "usec" ");"
.HP \w'int\ sd_event_source_set_time('u
.BI "int sd_event_source_set_time(sd_event_source\ *" "source" ", usec_t\ " "usec" ");"
.HP \w'int\ sd_event_source_get_time_accuracy('u
.BI "int sd_event_source_get_time_accuracy(sd_event_source\ *" "source" ", usec_t\ *" "usec" ");"
.HP \w'int\ sd_event_source_set_time_accuracy('u
.BI "int sd_event_source_set_time_accuracy(sd_event_source\ *" "source" ", usec_t\ " "usec" ");"
.HP \w'int\ sd_event_source_get_time_clock('u
.BI "int sd_event_source_get_time_clock(sd_event_source\ *" "source" ", clockid_t\ *" "clock" ");"
.SH "DESCRIPTION"
.PP
\fBsd_event_add_time()\fR
adds a new timer event source to an event loop object\&. The event loop is specified in
\fIevent\fR, the event source is returned in the
\fIsource\fR
parameter\&. The
\fIclock\fR
parameter takes a clock identifier, one of
\fBCLOCK_REALTIME\fR,
\fBCLOCK_MONOTONIC\fR
and
\fBCLOCK_BOOTTIME_ALARM\fR\&. See
\fBtimerfd_create\fR(2)
for details regarding the various types of clocks\&. The
\fIusec\fR
parameter takes a time value in microseconds, relative to the clock\*(Aqs epoch specifying when the timer shall elapse the earliest\&. The
\fIaccuracy\fR
parameter takes an additional accuracy value in microseconds specifying a time the timer event may be delayed\&. Specify 0 for selecting the default accuracy (250ms)\&. Specify 1 for most accurate timers\&. Consider specifying 60000000 or larger (1h) for long\-running events that may be delayed substantially\&. Picking higher accuracy values allows the system to coalesce timer events more aggressively, thus improving power efficiency\&. The
\fIhandler\fR
shall reference a function to call when the timer elapses\&. The handler function will be passed the
\fIuserdata\fR
pointer, which may be chosen freely by the caller\&. The handler is also passed the configured time it was triggered, however it might actually have been called at a slightly later time, subject to the specified accuracy value, the kernel timer slack (see
\fBprctl\fR(2)) and additional scheduling latencies\&.
.PP
By default, the timer will elapse once (\fBSD_EVENT_ONESHOT\fR), but this may be changed with
\fBsd_event_source_set_enabled\fR(3)\&. If the handler function returns a negative error code, it will be disabled after the invocation, even if
\fBSD_EVENT_ON\fR
mode is set\&.
.PP
\fBsd_event_source_get_time()\fR
retrieves the configured time value of a timer event source created previously with
\fBsd_event_add_time()\fR\&. It takes the event source object and a pointer to a variable to store the time in microseconds in\&.
.PP
\fBsd_event_source_set_time()\fR
changes the configured time value of a timer event source created previously with
\fBsd_event_add_time()\fR\&. It takes the event source object and a time relative to the selected clock\*(Aqs epoch, in microseconds\&.
.PP
\fBsd_event_source_get_time_accuracy()\fR
retrieves the configured accuracy value of a timer event source created previously with
\fBsd_event_add_time()\fR\&. It takes the event source object and a pointer to a variable to store the accuracy in microseconds in\&.
.PP
\fBsd_event_source_set_time_accuracy()\fR
changes the configured accuracy of a timer event source created previously with
\fBsd_event_add_time()\fR\&. It takes the event source object and an accuracy, in microseconds\&.
.PP
\fBsd_event_source_get_time_clock()\fR
retrieves the configured clock of a timer event source created previously with
\fBsd_event_add_time()\fR\&. It takes the event source object and a pointer to a variable to store the clock identifier in\&.
.SH "RETURN VALUE"
.PP
On success, these functions return 0 or a positive integer\&. On failure, they return a negative errno\-style error code\&.
.SH "ERRORS"
.PP
Returned errors may indicate the following problems:
.PP
\fB\-ENOMEM\fR
.RS 4
Not enough memory to allocate an object\&.
.RE
.PP
\fB\-EINVAL\fR
.RS 4
An invalid argument has been passed\&.
.RE
.PP
\fB\-ESTALE\fR
.RS 4
The event loop is already terminated\&.
.RE
.PP
\fB\-ECHILD\fR
.RS 4
The event loop has been created in a different process\&.
.RE
.PP
\fB\-ENOTSUP\fR
.RS 4
The selected clock is not supported by the event loop implementation\&.
.RE
.SH "NOTES"
.PP
\fBsd_event_add_time()\fR
and the other functions described here are available as a shared library, which can be compiled and linked to with the
\fBlibsystemd\fR\ \&\fBpkg-config\fR(1)
file\&.
.SH "SEE ALSO"
.PP
\fBsystemd\fR(1),
\fBsd-event\fR(3),
\fBsd_event_new\fR(3),
\fBsd_event_add_signal\fR(3),
\fBsd_event_add_child\fR(3),
\fBsd_event_add_defer\fR(3),
\fBclock_gettime\fR(2),
\fBsd_event_source_set_enabled\fR(3)