source: rtems-docs/posix_users/clock.rst @ 36def91

4.115
Last change on this file since 36def91 was 489740f, checked in by Chris Johns <chrisj@…>, on 05/20/16 at 02:47:09

Set SPDX License Identifier in each source file.

  • Property mode set to 100644
File size: 7.0 KB
Line 
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
6Clock Manager
7#############
8
9Introduction
10============
11
12The clock manager provides services two primary classes of services.  The first
13focuses on obtaining and setting the current date and time.  The other category
14of services focus on allowing a thread to delay for a specific length of time.
15
16The 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
34Background
35==========
36
37There is currently no text in this section.
38
39Operations
40==========
41
42There is currently no text in this section.
43
44Directives
45==========
46
47This section details the clock manager's directives.  A subsection is dedicated
48to each of this manager's directives and describes the calling sequence,
49related constants, usage, and status codes.
50
51.. _clock_gettime:
52
53clock_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
70On 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
84NONE
85
86.. _clock_settime:
87
88clock_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
105On 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
121NONE
122
123.. _clock_getres:
124
125clock_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
142On 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
156If ``res`` is ``NULL``, then the resolution is not returned.
157
158.. _sleep:
159
160sleep - 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
176This routine returns the number of unslept seconds.
177
178**DESCRIPTION:**
179
180The ``sleep()`` function delays the calling thread by the specified number of
181``seconds``.
182
183**NOTES:**
184
185This call is interruptible by a signal.
186
187.. _usleep:
188
189usleep - 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
208This routine returns the number of unslept seconds.
209
210**DESCRIPTION:**
211
212The ``sleep()`` function delays the calling thread by the specified number of
213``seconds``.
214
215The ``usleep()`` function suspends the calling thread from execution until
216either the number of microseconds specified by the ``useconds`` argument has
217elapsed or a signal is delivered to the calling thread and its action is to
218invoke a signal-catching function or to terminate the process.
219
220Because of other activity, or because of the time spent in processing the call,
221the actual length of time the thread is blocked may be longer than the amount
222of time specified.
223
224**NOTES:**
225
226This call is interruptible by a signal.
227
228The Single UNIX Specification allows this service to be implemented using the
229same 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
234nanosleep - 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
251On 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
268This call is interruptible by a signal.
269
270.. _gettimeofday:
271
272gettimeofday - 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
290On 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
304This routine returns the current time of day in the ``tp`` structure.
305
306**NOTES:**
307
308Currently, the timezone information is not supported. The ``tzp`` argument is
309ignored.
310
311.. _time:
312
313time - 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
329This 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
334seconds
335
336If ``tloc`` in non null, the return value is also stored in the memory pointed
337to by ``t``.
338
339**NOTES:**
340
341NONE
Note: See TracBrowser for help on using the repository browser.