Debian Codegraph @

upstream/debian-unstable/man3/sd_event_add_time.3

raw
1 '\" t
2 .TH "SD_EVENT_ADD_TIME" "3" "" "systemd 261~rc3" "sd_event_add_time"
3 .\" -----------------------------------------------------------------
4 .\" * Define some portability stuff
5 .\" -----------------------------------------------------------------
6 .\" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
7 .\" http://bugs.debian.org/507673
8 .\" http://lists.gnu.org/archive/html/groff/2009-02/msg00013.html
9 .\" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
10 .ie \n(.g .ds Aq \(aq
11 .el .ds Aq '
12 .\" -----------------------------------------------------------------
13 .\" * set default formatting
14 .\" -----------------------------------------------------------------
15 .\" disable hyphenation
16 .nh
17 .\" disable justification (adjust text to left margin only)
18 .ad l
19 .\" -----------------------------------------------------------------
20 .\" * MAIN CONTENT STARTS HERE *
21 .\" -----------------------------------------------------------------
22 .SH "NAME"
23 sd_event_add_time, sd_event_add_time_relative, sd_event_source_get_time, sd_event_source_set_time, sd_event_source_set_time_relative, sd_event_source_get_time_accuracy, sd_event_source_set_time_accuracy, sd_event_source_get_time_clock, sd_event_time_handler_t \- Add a timer event source to an event loop
24 .SH "SYNOPSIS"
25 .sp
26 .ft B
27 .nf
28 #include <systemd/sd\-event\&.h>
29 .fi
30 .ft
31 .sp
32 .ft B
33 .nf
34 typedef struct sd_event_source sd_event_source;
35 .fi
36 .ft
37 .HP \w'typedef\ int\ (*sd_event_time_handler_t)('u
38 .BI "typedef int (*sd_event_time_handler_t)(sd_event_source\ *" "s" ", uint64_t\ " "usec" ", void\ *" "userdata" ");"
39 .HP \w'int\ sd_event_add_time('u
40 .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" ");"
41 .HP \w'int\ sd_event_add_time_relative('u
42 .BI "int sd_event_add_time_relative(sd_event\ *" "event" ", sd_event_source\ **" "source" ", clockid_t\ " "clock" ", uint64_t\ " "usec" ", uint64_t\ " "accuracy" ", sd_event_time_handler_t\ " "handler" ", void\ *" "userdata" ");"
43 .HP \w'int\ sd_event_source_get_time('u
44 .BI "int sd_event_source_get_time(sd_event_source\ *" "source" ", uint64_t\ *" "ret" ");"
45 .HP \w'int\ sd_event_source_set_time('u
46 .BI "int sd_event_source_set_time(sd_event_source\ *" "source" ", uint64_t\ " "usec" ");"
47 .HP \w'int\ sd_event_source_set_time_relative('u
48 .BI "int sd_event_source_set_time_relative(sd_event_source\ *" "source" ", uint64_t\ " "usec" ");"
49 .HP \w'int\ sd_event_source_get_time_accuracy('u
50 .BI "int sd_event_source_get_time_accuracy(sd_event_source\ *" "source" ", uint64_t\ *" "ret" ");"
51 .HP \w'int\ sd_event_source_set_time_accuracy('u
52 .BI "int sd_event_source_set_time_accuracy(sd_event_source\ *" "source" ", uint64_t\ " "usec" ");"
53 .HP \w'int\ sd_event_source_get_time_clock('u
54 .BI "int sd_event_source_get_time_clock(sd_event_source\ *" "source" ", clockid_t\ *" "ret" ");"
55 .SH "DESCRIPTION"
56 .PP
57 \fBsd_event_add_time()\fR
58 adds a new timer event source to an event loop\&. The event loop object is specified in the
59 \fIevent\fR
60 parameter, the event source object is returned in the
61 \fIsource\fR
62 parameter\&. The
63 \fIclock\fR
64 parameter takes a clock identifier, one of
65 \fBCLOCK_REALTIME\fR,
66 \fBCLOCK_MONOTONIC\fR,
67 \fBCLOCK_BOOTTIME\fR,
68 \fBCLOCK_REALTIME_ALARM\fR, or
69 \fBCLOCK_BOOTTIME_ALARM\fR\&. See
70 \fBtimerfd_create\fR(2)
71 for details regarding the various types of clocks\&. The
72 \fIusec\fR
73 parameter specifies the earliest time, in microseconds (μs), relative to the clock\*(Aqs epoch, when the timer shall be triggered\&. If a time already in the past is specified (including
74 \fB0\fR), this timer source "fires" immediately and is ready to be dispatched\&. If the parameter is specified as
75 \fBUINT64_MAX\fR
76 the timer event will never elapse, which may be used as an alternative to explicitly disabling a timer event source with
77 \fBsd_event_source_set_enabled\fR(3)\&. The
78 \fIaccuracy\fR
79 parameter specifies an additional accuracy value in μs specifying how much the timer event may be delayed\&. Use
80 \fB0\fR
81 to select the default accuracy (250ms)\&. Use 1μs for maximum accuracy\&. Consider specifying 60000000μs (1min) or larger for long\-running events that may be delayed substantially\&. Picking higher accuracy values allows the system to coalesce timer events more aggressively, improving power efficiency\&.
82 .PP
83 The
84 \fIhandler\fR
85 is a function to call when the timer elapses or
86 \fBNULL\fR\&. The
87 \fIuserdata\fR
88 pointer will be passed to the handler function, and may be chosen freely by the caller\&. The configured trigger time is also passed to the handler, even if the call actually happens slightly later, subject to the specified accuracy value, the kernel timer slack (see
89 \fBprctl\fR(2)), and additional scheduling latencies\&. To query the actual time the handler was called use
90 \fBsd_event_now\fR(3)\&. The handler may return negative to signal an error (see below), other return values are ignored\&. If
91 \fIhandler\fR
92 is
93 \fBNULL\fR, a default handler that calls
94 \fBsd_event_exit\fR(3)
95 will be used\&.
96 .PP
97 By default, the timer will elapse once (\fBSD_EVENT_ONESHOT\fR), but this may be changed with
98 \fBsd_event_source_set_enabled\fR(3)\&. If the handler function returns a negative error code, it will either be disabled after the invocation, even if the
99 \fBSD_EVENT_ON\fR
100 mode was requested before, or it will cause the loop to terminate, see
101 \fBsd_event_source_set_exit_on_failure\fR(3)\&. Note that a timer event set to
102 \fBSD_EVENT_ON\fR
103 will fire continuously unless its configured time is updated using
104 \fBsd_event_source_set_time()\fR\&.
105 .PP
106 \fBsd_event_add_time_relative()\fR
107 is like
108 \fBsd_event_add_time()\fR, but takes a relative time specification\&. It\*(Aqs relative to the current time of the event loop iteration, as returned by
109 \fBsd_event_now\fR(3)\&.
110 .PP
111 To destroy an event source object use
112 \fBsd_event_source_unref\fR(3), but note that the event source is only removed from the event loop when all references to the event source are dropped\&. To make sure an event source does not fire anymore, even if it is still referenced, disable the event source using
113 \fBsd_event_source_set_enabled\fR(3)
114 with
115 \fBSD_EVENT_OFF\fR\&.
116 .PP
117 If the second parameter of
118 \fBsd_event_add_time()\fR
119 is
120 \fBNULL\fR
121 no reference to the event source object is returned\&. In this case, the event source is considered "floating", and will be destroyed implicitly when the event loop itself is destroyed\&.
122 .PP
123 If the
124 \fIhandler\fR
125 parameter to
126 \fBsd_event_add_time()\fR
127 is
128 \fBNULL\fR, and the event source fires, this will be considered a request to exit the event loop\&. In this case, the
129 \fIuserdata\fR
130 parameter, cast to an integer, is passed as the exit code parameter to
131 \fBsd_event_exit\fR(3)\&.
132 .PP
133 Use
134 \fBCLOCK_BOOTTIME_ALARM\fR
135 and
136 \fBCLOCK_REALTIME_ALARM\fR
137 to define event sources that may wake up the system from suspend\&.
138 .PP
139 In order to set up relative timers (that is, relative to the current time), retrieve the current time via
140 \fBsd_event_now\fR(3), add the desired timespan to it, and use the result as the
141 \fIusec\fR
142 parameter to
143 \fBsd_event_add_time()\fR\&.
144 .PP
145 In order to set up repetitive timers (that is, timers that are triggered in regular intervals), set up the timer normally, for the first invocation\&. Each time the event handler is invoked, update the timer\*(Aqs trigger time with
146 \fBsd_event_source_set_time\fR(3)
147 for the next timer iteration, and reenable the timer using
148 \fBsd_event_source_set_enabled()\fR\&. To calculate the next point in time to pass to
149 \fBsd_event_source_set_time()\fR, either use as base the
150 \fIusec\fR
151 parameter passed to the timer callback, or the timestamp returned by
152 \fBsd_event_now()\fR\&. In the former case timer events will be regular, while in the latter case, the scheduling latency will keep accumulating on the timer\&.
153 .PP
154 \fBsd_event_source_get_time()\fR
155 retrieves the configured time value of an event source created previously with
156 \fBsd_event_add_time()\fR
157 or
158 \fBsd_event_add_time_relative()\fR\&. It takes the event source object and a pointer to a variable to store the time in, relative to the selected clock\*(Aqs epoch, in μs\&. The returned value is relative to the epoch, even if the event source was created with a relative time via
159 \fBsd_event_add_time_relative()\fR\&.
160 .PP
161 \fBsd_event_source_set_time()\fR
162 changes the time of an event source created previously with
163 \fBsd_event_add_time()\fR
164 or
165 \fBsd_event_add_time_relative()\fR\&. It takes the event source object and a time relative to the selected clock\*(Aqs epoch, in μs\&.
166 .PP
167 \fBsd_event_source_set_time_relative()\fR
168 is similar to
169 \fBsd_event_source_set_time()\fR, but takes a time relative to the current time of the event loop iteration, as returned by
170 \fBsd_event_now()\fR\&.
171 .PP
172 \fBsd_event_source_get_time_accuracy()\fR
173 retrieves the configured accuracy value of an event source created previously with
174 \fBsd_event_add_time()\fR\&. It takes the event source object and a pointer to a variable to store the accuracy in\&. The accuracy is specified in μs\&.
175 .PP
176 \fBsd_event_source_set_time_accuracy()\fR
177 changes the configured accuracy of a timer event source created previously with
178 \fBsd_event_add_time()\fR\&. It takes the event source object and accuracy, in μs\&.
179 .PP
180 \fBsd_event_source_get_time_clock()\fR
181 retrieves the configured clock of an event source created previously with
182 \fBsd_event_add_time()\fR\&. It takes the event source object and a pointer to a variable to store the clock identifier in\&.
183 .SH "RETURN VALUE"
184 .PP
185 On success, these functions return 0 or a positive integer\&. On failure, they return a negative errno\-style error code\&.
186 .SS "Errors"
187 .PP
188 Returned values may indicate the following problems:
189 .PP
190 \fB\-ENOMEM\fR
191 .RS 4
192 Not enough memory to allocate an object\&.
193 .RE
194 .PP
195 \fB\-EINVAL\fR
196 .RS 4
197 An invalid argument has been passed\&.
198 .RE
199 .PP
200 \fB\-ESTALE\fR
201 .RS 4
202 The event loop is already terminated\&.
203 .RE
204 .PP
205 \fB\-ECHILD\fR
206 .RS 4
207 The event loop has been created in a different process, library or module instance\&.
208 .RE
209 .PP
210 \fB\-EOPNOTSUPP\fR
211 .RS 4
212 The selected clock is not supported by the event loop implementation\&.
213 .RE
214 .PP
215 \fB\-EDOM\fR
216 .RS 4
217 The passed event source is not a timer event source\&.
218 .RE
219 .PP
220 \fB\-EOVERFLOW\fR
221 .RS 4
222 The passed relative time is outside of the allowed range for time values (i\&.e\&. the specified value added to the current time is outside the 64 bit unsigned integer range)\&.
223 .sp
224 Added in version 247\&.
225 .RE
226 .SH "NOTES"
227 .PP
228 Functions described here are available as a shared library, which can be compiled against and linked to with the
229 \fBlibsystemd\fR\ \&\fBpkg-config\fR(1)
230 file\&.
231 .PP
232 The code described here uses
233 \fBgetenv\fR(3), which is declared to be not multi\-thread\-safe\&. This means that the code calling the functions described here must not call
234 \fBsetenv\fR(3)
235 from a parallel thread\&. It is recommended to only do calls to
236 \fBsetenv()\fR
237 from an early phase of the program when no other threads have been started\&.
238 .SH "HISTORY"
239 .PP
240 \fBsd_event_add_time()\fR,
241 \fBsd_event_source_get_time()\fR,
242 \fBsd_event_source_set_time()\fR,
243 \fBsd_event_source_get_time_accuracy()\fR,
244 \fBsd_event_source_set_time_accuracy()\fR, and
245 \fBsd_event_source_get_time_clock()\fR
246 were added in version 213\&.
247 .PP
248 \fBsd_event_time_handler_t()\fR
249 was added in version 217\&.
250 .PP
251 \fBsd_event_add_time_relative()\fR
252 and
253 \fBsd_event_source_set_time_relative()\fR
254 were added in version 247\&.
255 .SH "SEE ALSO"
256 .PP
257 \fBsystemd\fR(1), \fBsd-event\fR(3), \fBsd_event_new\fR(3), \fBsd_event_now\fR(3), \fBsd_event_add_io\fR(3), \fBsd_event_add_signal\fR(3), \fBsd_event_add_child\fR(3), \fBsd_event_add_inotify\fR(3), \fBsd_event_add_defer\fR(3), \fBsd_event_source_set_enabled\fR(3), \fBsd_event_source_set_priority\fR(3), \fBsd_event_source_set_userdata\fR(3), \fBsd_event_source_set_description\fR(3), \fBsd_event_source_set_floating\fR(3), \fBclock_gettime\fR(2), \fBtimerfd_create\fR(2), \fBprctl\fR(2)