summaryrefslogtreecommitdiffstats
path: root/posix_users/clock.rst
blob: f37c1b94effa1a4b40e52c67999c2234f2967a69 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
Clock Manager
#############

Introduction
============

The clock manager provides services two primary classes
of services.  The first focuses on obtaining and setting
the current date and time.  The other category of services
focus on allowing a thread to delay for a specific length
of time.

The directives provided by the clock manager are:

- ``clock_gettime`` - Obtain Time of Day

- ``clock_settime`` - Set Time of Day

- ``clock_getres`` - Get Clock Resolution

- ``sleep`` - Delay Process Execution

- ``usleep`` - Delay Process Execution in Microseconds

- ``nanosleep`` - Delay with High Resolution

- ``gettimeofday`` - Get the Time of Day

- ``time`` - Get time in seconds

Background
==========

There is currently no text in this section.

Operations
==========

There is currently no text in this section.

Directives
==========

This section details the clock manager’s directives.
A subsection is dedicated to each of this manager’s directives
and describes the calling sequence, related constants, usage,
and status codes.

clock_gettime - Obtain Time of Day
----------------------------------
.. index:: clock_gettime
.. index:: obtain time of day

**CALLING SEQUENCE:**

.. code:: c

    #include <time.h>
    int clock_gettime(
    clockid_t        clock_id,
    struct timespec \*tp
    );

**STATUS CODES:**

On error, this routine returns -1 and sets errno to one of the following:

*EINVAL*
    The tp pointer parameter is invalid.

*EINVAL*
    The clock_id specified is invalid.

**DESCRIPTION:**

**NOTES:**

NONE

clock_settime - Set Time of Day
-------------------------------
.. index:: clock_settime
.. index:: set time of day

**CALLING SEQUENCE:**

.. code:: c

    #include <time.h>
    int clock_settime(
    clockid_t              clock_id,
    const struct timespec \*tp
    );

**STATUS CODES:**

On error, this routine returns -1 and sets errno to one of the following:

*EINVAL*
    The tp pointer parameter is invalid.

*EINVAL*
    The clock_id specified is invalid.

*EINVAL*
    The contents of the tp structure are invalid.

**DESCRIPTION:**

**NOTES:**

NONE

clock_getres - Get Clock Resolution
-----------------------------------
.. index:: clock_getres
.. index:: get clock resolution

**CALLING SEQUENCE:**

.. code:: c

    #include <time.h>
    int clock_getres(
    clockid_t        clock_id,
    struct timespec \*res
    );

**STATUS CODES:**

On error, this routine returns -1 and sets errno to one of the following:

*EINVAL*
    The res pointer parameter is invalid.

*EINVAL*
    The clock_id specified is invalid.

**DESCRIPTION:**

**NOTES:**

If res is NULL, then the resolution is not returned.

sleep - Delay Process Execution
-------------------------------
.. index:: sleep
.. index:: delay process execution

**CALLING SEQUENCE:**

.. code:: c

    #include <unistd.h>
    unsigned int sleep(
    unsigned int seconds
    );

**STATUS CODES:**

This routine returns the number of unslept seconds.

**DESCRIPTION:**

The ``sleep()`` function delays the calling thread by the specified
number of ``seconds``.

**NOTES:**

This call is interruptible by a signal.

usleep - Delay Process Execution in Microseconds
------------------------------------------------
.. index:: usleep
.. index:: delay process execution
.. index:: delay process execution
.. index:: usecs delay process execution
.. index:: microsecond delay process execution

**CALLING SEQUENCE:**

.. code:: c

    #include <time.h>
    useconds_t usleep(
    useconds_t useconds
    );

**STATUS CODES:**

This routine returns the number of unslept seconds.

**DESCRIPTION:**

The ``sleep()`` function delays the calling thread by the specified
number of ``seconds``.

The ``usleep()`` function suspends the calling thread from execution
until either the number of microseconds specified by the``useconds`` argument has elapsed or a signal is delivered to the
calling thread and its action is to invoke a signal-catching function
or to terminate the process.

Because of other activity, or because of the time spent in
processing the call, the actual length of time the thread is
blocked may be longer than
the amount of time specified.

**NOTES:**

This call is interruptible by a signal.

The Single UNIX Specification allows this service to be implemented using
the same timer as that used by the ``alarm()`` service.  This is*NOT* the case for *RTEMS* and this call has no interaction with
the ``SIGALRM`` signal.

nanosleep - Delay with High Resolution
--------------------------------------
.. index:: nanosleep
.. index:: delay with high resolution

**CALLING SEQUENCE:**

.. code:: c

    #include <time.h>
    int nanosleep(
    const struct timespec \*rqtp,
    struct timespec       \*rmtp
    );

**STATUS CODES:**

On error, this routine returns -1 and sets errno to one of the following:

*EINTR*
    The routine was interrupted by a signal.

*EAGAIN*
    The requested sleep period specified negative seconds or nanoseconds.

*EINVAL*
    The requested sleep period specified an invalid number for the nanoseconds
    field.

**DESCRIPTION:**

**NOTES:**

This call is interruptible by a signal.

gettimeofday - Get the Time of Day
----------------------------------
.. index:: gettimeofday
.. index:: get the time of day

**CALLING SEQUENCE:**

.. code:: c

    #include <sys/time.h>
    #include <unistd.h>
    int gettimeofday(
    struct timeval  \*tp,
    struct timezone \*tzp
    );

**STATUS CODES:**

On error, this routine returns -1 and sets ``errno`` as appropriate.

*EPERM*
    ``settimeofdat`` is called by someone other than the superuser.

*EINVAL*
    Timezone (or something else) is invalid.

*EFAULT*
    One of ``tv`` or ``tz`` pointed outside your accessible address
    space

**DESCRIPTION:**

This routine returns the current time of day in the ``tp`` structure.

**NOTES:**

Currently, the timezone information is not supported. The ``tzp``
argument is ignored.

time - Get time in seconds
--------------------------
.. index:: time
.. index:: get time in seconds

**CALLING SEQUENCE:**

.. code:: c

    #include <time.h>
    int time(
    time_t \*tloc
    );

**STATUS CODES:**

This routine returns the number of seconds since the Epoch.

**DESCRIPTION:**

``time`` returns the time since 00:00:00 GMT, January 1, 1970,
measured in seconds

If ``tloc`` in non null, the return value is also stored in the
memory pointed to by ``t``.

**NOTES:**

NONE

.. COMMENT: This is the chapter from the RTEMS POSIX 1003.1b API User's Guide that

.. COMMENT: documents the services provided by the timer @c  manager.