1ZCLOCK(3) CZMQ Manual ZCLOCK(3)
2
3
4
6 zclock - Class for millisecond clocks and delays
7
9 // This is a stable class, and may not change except for emergencies. It
10 // is provided in stable builds.
11 // Sleep for a number of milliseconds
12 CZMQ_EXPORT void
13 zclock_sleep (int msecs);
14
15 // Return current system clock as milliseconds. Note that this clock can
16 // jump backwards (if the system clock is changed) so is unsafe to use for
17 // timers and time offsets. Use zclock_mono for that instead.
18 CZMQ_EXPORT int64_t
19 zclock_time (void);
20
21 // Return current monotonic clock in milliseconds. Use this when you compute
22 // time offsets. The monotonic clock is not affected by system changes and
23 // so will never be reset backwards, unlike a system clock.
24 CZMQ_EXPORT int64_t
25 zclock_mono (void);
26
27 // Return current monotonic clock in microseconds. Use this when you compute
28 // time offsets. The monotonic clock is not affected by system changes and
29 // so will never be reset backwards, unlike a system clock.
30 CZMQ_EXPORT int64_t
31 zclock_usecs (void);
32
33 // Return formatted date/time as fresh string. Free using zstr_free().
34 // Caller owns return value and must destroy it when done.
35 CZMQ_EXPORT char *
36 zclock_timestr (void);
37
38 // Self test of this class.
39 CZMQ_EXPORT void
40 zclock_test (bool verbose);
41
42 Please add '@interface' section in './../src/zclock.c'.
43
45 The zclock class provides essential sleep and system time functions,
46 used to slow down threads for testing, and calculate timers for
47 polling. Wraps the non-portable system calls in a simple portable API.
48
49 The Win32 Sleep() call defaults to 16ms resolution unless the system
50 timer resolution is increased with a call to timeBeginPeriod()
51 permitting 1ms granularity.
52
54 From zclock_test method.
55
56 int64_t start = zclock_time ();
57 zclock_sleep (10);
58 assert ((zclock_time () - start) >= 10);
59 start = zclock_mono ();
60 int64_t usecs = zclock_usecs ();
61 zclock_sleep (10);
62 assert ((zclock_mono () - start) >= 10);
63 assert ((zclock_usecs () - usecs) >= 10000);
64 char *timestr = zclock_timestr ();
65 if (verbose)
66 puts (timestr);
67 freen (timestr);
68
69 #if defined (__WINDOWS__)
70 zsys_shutdown();
71 #endif
72
73
75 The czmq manual was written by the authors in the AUTHORS file.
76
78 Main web site:
79
80 Report bugs to the email <zeromq-dev@lists.zeromq.org[1]>
81
83 Copyright (c) the Contributors as noted in the AUTHORS file. This file
84 is part of CZMQ, the high-level C binding for 0MQ:
85 http://czmq.zeromq.org. This Source Code Form is subject to the terms
86 of the Mozilla Public License, v. 2.0. If a copy of the MPL was not
87 distributed with this file, You can obtain one at
88 http://mozilla.org/MPL/2.0/. LICENSE included with the czmq
89 distribution.
90
92 1. zeromq-dev@lists.zeromq.org
93 mailto:zeromq-dev@lists.zeromq.org
94
95
96
97CZMQ 4.2.1 02/01/2021 ZCLOCK(3)