1 | .. comment SPDX-License-Identifier: CC-BY-SA-4.0 |
---|
2 | |
---|
3 | .. COMMENT: This is the chapter from the RTEMS POSIX 1003.1b API User's Guide that |
---|
4 | .. COMMENT: documents the services provided by the timer @c manager. |
---|
5 | |
---|
6 | Clock Manager |
---|
7 | ############# |
---|
8 | |
---|
9 | Introduction |
---|
10 | ============ |
---|
11 | |
---|
12 | The clock manager provides services two primary classes of services. The first |
---|
13 | focuses on obtaining and setting the current date and time. The other category |
---|
14 | of services focus on allowing a thread to delay for a specific length of time. |
---|
15 | |
---|
16 | The directives provided by the clock manager are: |
---|
17 | |
---|
18 | - clock_gettime_ - Obtain Time of Day |
---|
19 | |
---|
20 | - clock_settime_ - Set Time of Day |
---|
21 | |
---|
22 | - clock_getres_ - Get Clock Resolution |
---|
23 | |
---|
24 | - sleep_ - Delay Process Execution |
---|
25 | |
---|
26 | - usleep_ - Delay Process Execution in Microseconds |
---|
27 | |
---|
28 | - nanosleep_ - Delay with High Resolution |
---|
29 | |
---|
30 | - gettimeofday_ - Get the Time of Day |
---|
31 | |
---|
32 | - time_ - Get time in seconds |
---|
33 | |
---|
34 | Background |
---|
35 | ========== |
---|
36 | |
---|
37 | There is currently no text in this section. |
---|
38 | |
---|
39 | Operations |
---|
40 | ========== |
---|
41 | |
---|
42 | There is currently no text in this section. |
---|
43 | |
---|
44 | Directives |
---|
45 | ========== |
---|
46 | |
---|
47 | This section details the clock manager's directives. A subsection is dedicated |
---|
48 | to each of this manager's directives and describes the calling sequence, |
---|
49 | related constants, usage, and status codes. |
---|
50 | |
---|
51 | .. _clock_gettime: |
---|
52 | |
---|
53 | clock_gettime - Obtain Time of Day |
---|
54 | ---------------------------------- |
---|
55 | .. index:: clock_gettime |
---|
56 | .. index:: obtain time of day |
---|
57 | |
---|
58 | **CALLING SEQUENCE:** |
---|
59 | |
---|
60 | .. code-block:: c |
---|
61 | |
---|
62 | #include <time.h> |
---|
63 | int clock_gettime( |
---|
64 | clockid_t clock_id, |
---|
65 | struct timespec *tp |
---|
66 | ); |
---|
67 | |
---|
68 | **STATUS CODES:** |
---|
69 | |
---|
70 | On error, this routine returns -1 and sets ``errno`` to one of the following: |
---|
71 | |
---|
72 | .. list-table:: |
---|
73 | :class: rtems-table |
---|
74 | |
---|
75 | * - ``EINVAL`` |
---|
76 | - The tp pointer parameter is invalid. |
---|
77 | * - ``EINVAL`` |
---|
78 | - The clock_id specified is invalid. |
---|
79 | |
---|
80 | **DESCRIPTION:** |
---|
81 | |
---|
82 | **NOTES:** |
---|
83 | |
---|
84 | NONE |
---|
85 | |
---|
86 | .. _clock_settime: |
---|
87 | |
---|
88 | clock_settime - Set Time of Day |
---|
89 | ------------------------------- |
---|
90 | .. index:: clock_settime |
---|
91 | .. index:: set time of day |
---|
92 | |
---|
93 | **CALLING SEQUENCE:** |
---|
94 | |
---|
95 | .. code-block:: c |
---|
96 | |
---|
97 | #include <time.h> |
---|
98 | int clock_settime( |
---|
99 | clockid_t clock_id, |
---|
100 | const struct timespec *tp |
---|
101 | ); |
---|
102 | |
---|
103 | **STATUS CODES:** |
---|
104 | |
---|
105 | On error, this routine returns -1 and sets ``errno`` to one of the following: |
---|
106 | |
---|
107 | .. list-table:: |
---|
108 | :class: rtems-table |
---|
109 | |
---|
110 | * - ``EINVAL`` |
---|
111 | - The tp pointer parameter is invalid. |
---|
112 | * - ``EINVAL`` |
---|
113 | - The clock_id specified is invalid. |
---|
114 | * - ``EINVAL`` |
---|
115 | - The contents of the tp structure are invalid. |
---|
116 | |
---|
117 | **DESCRIPTION:** |
---|
118 | |
---|
119 | **NOTES:** |
---|
120 | |
---|
121 | NONE |
---|
122 | |
---|
123 | .. _clock_getres: |
---|
124 | |
---|
125 | clock_getres - Get Clock Resolution |
---|
126 | ----------------------------------- |
---|
127 | .. index:: clock_getres |
---|
128 | .. index:: get clock resolution |
---|
129 | |
---|
130 | **CALLING SEQUENCE:** |
---|
131 | |
---|
132 | .. code-block:: c |
---|
133 | |
---|
134 | #include <time.h> |
---|
135 | int clock_getres( |
---|
136 | clockid_t clock_id, |
---|
137 | struct timespec *res |
---|
138 | ); |
---|
139 | |
---|
140 | **STATUS CODES:** |
---|
141 | |
---|
142 | On error, this routine returns -1 and sets ``errno`` to one of the following: |
---|
143 | |
---|
144 | .. list-table:: |
---|
145 | :class: rtems-table |
---|
146 | |
---|
147 | * - ``EINVAL`` |
---|
148 | - The res pointer parameter is invalid. |
---|
149 | * - ``EINVAL`` |
---|
150 | - The clock_id specified is invalid. |
---|
151 | |
---|
152 | **DESCRIPTION:** |
---|
153 | |
---|
154 | **NOTES:** |
---|
155 | |
---|
156 | If ``res`` is ``NULL``, then the resolution is not returned. |
---|
157 | |
---|
158 | .. _sleep: |
---|
159 | |
---|
160 | sleep - Delay Process Execution |
---|
161 | ------------------------------- |
---|
162 | .. index:: sleep |
---|
163 | .. index:: delay process execution |
---|
164 | |
---|
165 | **CALLING SEQUENCE:** |
---|
166 | |
---|
167 | .. code-block:: c |
---|
168 | |
---|
169 | #include <unistd.h> |
---|
170 | unsigned int sleep( |
---|
171 | unsigned int seconds |
---|
172 | ); |
---|
173 | |
---|
174 | **STATUS CODES:** |
---|
175 | |
---|
176 | This routine returns the number of unslept seconds. |
---|
177 | |
---|
178 | **DESCRIPTION:** |
---|
179 | |
---|
180 | The ``sleep()`` function delays the calling thread by the specified number of |
---|
181 | ``seconds``. |
---|
182 | |
---|
183 | **NOTES:** |
---|
184 | |
---|
185 | This call is interruptible by a signal. |
---|
186 | |
---|
187 | .. _usleep: |
---|
188 | |
---|
189 | usleep - Delay Process Execution in Microseconds |
---|
190 | ------------------------------------------------ |
---|
191 | .. index:: usleep |
---|
192 | .. index:: delay process execution |
---|
193 | .. index:: delay process execution |
---|
194 | .. index:: usecs delay process execution |
---|
195 | .. index:: microsecond delay process execution |
---|
196 | |
---|
197 | **CALLING SEQUENCE:** |
---|
198 | |
---|
199 | .. code-block:: c |
---|
200 | |
---|
201 | #include <time.h> |
---|
202 | useconds_t usleep( |
---|
203 | useconds_t useconds |
---|
204 | ); |
---|
205 | |
---|
206 | **STATUS CODES:** |
---|
207 | |
---|
208 | This routine returns the number of unslept seconds. |
---|
209 | |
---|
210 | **DESCRIPTION:** |
---|
211 | |
---|
212 | The ``sleep()`` function delays the calling thread by the specified number of |
---|
213 | ``seconds``. |
---|
214 | |
---|
215 | The ``usleep()`` function suspends the calling thread from execution until |
---|
216 | either the number of microseconds specified by the ``useconds`` argument has |
---|
217 | elapsed or a signal is delivered to the calling thread and its action is to |
---|
218 | invoke a signal-catching function or to terminate the process. |
---|
219 | |
---|
220 | Because of other activity, or because of the time spent in processing the call, |
---|
221 | the actual length of time the thread is blocked may be longer than the amount |
---|
222 | of time specified. |
---|
223 | |
---|
224 | **NOTES:** |
---|
225 | |
---|
226 | This call is interruptible by a signal. |
---|
227 | |
---|
228 | The Single UNIX Specification allows this service to be implemented using the |
---|
229 | same timer as that used by the ``alarm()`` service. This is *NOT* the case for |
---|
230 | *RTEMS* and this call has no interaction with the ``SIGALRM`` signal. |
---|
231 | |
---|
232 | .. _nanosleep: |
---|
233 | |
---|
234 | nanosleep - Delay with High Resolution |
---|
235 | -------------------------------------- |
---|
236 | .. index:: nanosleep |
---|
237 | .. index:: delay with high resolution |
---|
238 | |
---|
239 | **CALLING SEQUENCE:** |
---|
240 | |
---|
241 | .. code-block:: c |
---|
242 | |
---|
243 | #include <time.h> |
---|
244 | int nanosleep( |
---|
245 | const struct timespec *rqtp, |
---|
246 | struct timespec *rmtp |
---|
247 | ); |
---|
248 | |
---|
249 | **STATUS CODES:** |
---|
250 | |
---|
251 | On error, this routine returns -1 and sets ``errno`` to one of the following: |
---|
252 | |
---|
253 | .. list-table:: |
---|
254 | :class: rtems-table |
---|
255 | |
---|
256 | * - ``EINTR`` |
---|
257 | - The routine was interrupted by a signal. |
---|
258 | * - ``EAGAIN`` |
---|
259 | - The requested sleep period specified negative seconds or nanoseconds. |
---|
260 | * - ``EINVAL`` |
---|
261 | - The requested sleep period specified an invalid number for the nanoseconds |
---|
262 | field. |
---|
263 | |
---|
264 | **DESCRIPTION:** |
---|
265 | |
---|
266 | **NOTES:** |
---|
267 | |
---|
268 | This call is interruptible by a signal. |
---|
269 | |
---|
270 | .. _gettimeofday: |
---|
271 | |
---|
272 | gettimeofday - Get the Time of Day |
---|
273 | ---------------------------------- |
---|
274 | .. index:: gettimeofday |
---|
275 | .. index:: get the time of day |
---|
276 | |
---|
277 | **CALLING SEQUENCE:** |
---|
278 | |
---|
279 | .. code-block:: c |
---|
280 | |
---|
281 | #include <sys/time.h> |
---|
282 | #include <unistd.h> |
---|
283 | int gettimeofday( |
---|
284 | struct timeval *tp, |
---|
285 | struct timezone *tzp |
---|
286 | ); |
---|
287 | |
---|
288 | **STATUS CODES:** |
---|
289 | |
---|
290 | On error, this routine returns -1 and sets ``errno`` as appropriate. |
---|
291 | |
---|
292 | .. list-table:: |
---|
293 | :class: rtems-table |
---|
294 | |
---|
295 | * - ``EPERM`` |
---|
296 | - ``settimeofdat`` is called by someone other than the superuser. |
---|
297 | * - ``EINVAL`` |
---|
298 | - Timezone (or something else) is invalid. |
---|
299 | * - ``EFAULT`` |
---|
300 | - One of ``tv`` or ``tz`` pointed outside your accessible address space |
---|
301 | |
---|
302 | **DESCRIPTION:** |
---|
303 | |
---|
304 | This routine returns the current time of day in the ``tp`` structure. |
---|
305 | |
---|
306 | **NOTES:** |
---|
307 | |
---|
308 | Currently, the timezone information is not supported. The ``tzp`` argument is |
---|
309 | ignored. |
---|
310 | |
---|
311 | .. _time: |
---|
312 | |
---|
313 | time - Get time in seconds |
---|
314 | -------------------------- |
---|
315 | .. index:: time |
---|
316 | .. index:: get time in seconds |
---|
317 | |
---|
318 | **CALLING SEQUENCE:** |
---|
319 | |
---|
320 | .. code-block:: c |
---|
321 | |
---|
322 | #include <time.h> |
---|
323 | int time( |
---|
324 | time_t *tloc |
---|
325 | ); |
---|
326 | |
---|
327 | **STATUS CODES:** |
---|
328 | |
---|
329 | This routine returns the number of seconds since the Epoch. |
---|
330 | |
---|
331 | **DESCRIPTION:** |
---|
332 | |
---|
333 | ``time`` returns the time since 00:00:00 GMT, January 1, 1970, measured in |
---|
334 | seconds |
---|
335 | |
---|
336 | If ``tloc`` in non null, the return value is also stored in the memory pointed |
---|
337 | to by ``t``. |
---|
338 | |
---|
339 | **NOTES:** |
---|
340 | |
---|
341 | NONE |
---|