Skip to content

Commit 7e752a3

Browse files
committed
Add clock_getres(3) and more clockid_t constants.
Signed-off-by: NODA, Kai <[email protected]>
1 parent f288e18 commit 7e752a3

File tree

6 files changed

+85
-27
lines changed

6 files changed

+85
-27
lines changed

src/unix/bsd/freebsdlike/dragonfly/mod.rs

Lines changed: 17 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ pub type clock_t = u64;
22
pub type ino_t = u64;
33
pub type nlink_t = u32;
44
pub type blksize_t = i64;
5+
pub type clockid_t = ::c_ulong;
56

67
pub type c_long = i64;
78
pub type c_ulong = u64;
@@ -96,23 +97,24 @@ pub const RLIM_NLIMITS: ::rlim_t = 12;
9697
pub const Q_GETQUOTA: ::c_int = 0x300;
9798
pub const Q_SETQUOTA: ::c_int = 0x400;
9899

99-
pub const CLOCK_REALTIME: ::c_ulong = 0;
100-
pub const CLOCK_VIRTUAL: ::c_ulong = 1;
101-
pub const CLOCK_PROF: ::c_ulong = 2;
102-
pub const CLOCK_MONOTONIC: ::c_ulong = 4;
103-
pub const CLOCK_UPTIME: ::c_ulong = 5;
104-
pub const CLOCK_UPTIME_PRECISE: ::c_ulong = 7;
105-
pub const CLOCK_UPTIME_FAST: ::c_ulong = 8;
106-
pub const CLOCK_REALTIME_PRECISE: ::c_ulong = 9;
107-
pub const CLOCK_REALTIME_FAST: ::c_ulong = 10;
108-
pub const CLOCK_MONOTONIC_PRECISE: ::c_ulong = 11;
109-
pub const CLOCK_MONOTONIC_FAST: ::c_ulong = 12;
110-
pub const CLOCK_SECOND: ::c_ulong = 13;
111-
pub const CLOCK_THREAD_CPUTIME_ID: ::c_ulong = 14;
112-
pub const CLOCK_PROCESS_CPUTIME_ID: ::c_ulong = 15;
100+
pub const CLOCK_REALTIME: clockid_t = 0;
101+
pub const CLOCK_VIRTUAL: clockid_t = 1;
102+
pub const CLOCK_PROF: clockid_t = 2;
103+
pub const CLOCK_MONOTONIC: clockid_t = 4;
104+
pub const CLOCK_UPTIME: clockid_t = 5;
105+
pub const CLOCK_UPTIME_PRECISE: clockid_t = 7;
106+
pub const CLOCK_UPTIME_FAST: clockid_t = 8;
107+
pub const CLOCK_REALTIME_PRECISE: clockid_t = 9;
108+
pub const CLOCK_REALTIME_FAST: clockid_t = 10;
109+
pub const CLOCK_MONOTONIC_PRECISE: clockid_t = 11;
110+
pub const CLOCK_MONOTONIC_FAST: clockid_t = 12;
111+
pub const CLOCK_SECOND: clockid_t = 13;
112+
pub const CLOCK_THREAD_CPUTIME_ID: clockid_t = 14;
113+
pub const CLOCK_PROCESS_CPUTIME_ID: clockid_t = 15;
113114

114115
extern {
115116
pub fn mprotect(addr: *mut ::c_void, len: ::size_t, prot: ::c_int)
116117
-> ::c_int;
117-
pub fn clock_gettime(clk_id: ::c_ulong, tp: *mut ::timespec) -> ::c_int;
118+
pub fn clock_getres(clk_id: clockid_t, tp: *mut ::timespec) -> ::c_int;
119+
pub fn clock_gettime(clk_id: clockid_t, tp: *mut ::timespec) -> ::c_int;
118120
}

src/unix/bsd/freebsdlike/freebsd/mod.rs

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ pub type clock_t = i32;
33
pub type ino_t = u32;
44
pub type nlink_t = u16;
55
pub type blksize_t = u32;
6+
pub type clockid_t = ::c_int;
67

78
pub type fsblkcnt_t = ::uint64_t;
89
pub type fsfilcnt_t = ::uint64_t;
@@ -60,16 +61,29 @@ pub const POSIX_FADV_NOREUSE: ::c_int = 5;
6061
pub const MADV_PROTECT: ::c_int = 10;
6162
pub const RUSAGE_THREAD: ::c_int = 1;
6263

63-
pub const CLOCK_REALTIME: ::c_int = 0;
64-
pub const CLOCK_MONOTONIC: ::c_int = 4;
64+
pub const CLOCK_REALTIME: clockid_t = 0;
65+
pub const CLOCK_VIRTUAL: clockid_t = 1;
66+
pub const CLOCK_PROF: clockid_t = 2;
67+
pub const CLOCK_MONOTONIC: clockid_t = 4;
68+
pub const CLOCK_UPTIME: clockid_t = 5;
69+
pub const CLOCK_UPTIME_PRECISE: clockid_t = 7;
70+
pub const CLOCK_UPTIME_FAST: clockid_t = 8;
71+
pub const CLOCK_REALTIME_PRECISE: clockid_t = 9;
72+
pub const CLOCK_REALTIME_FAST: clockid_t = 10;
73+
pub const CLOCK_MONOTONIC_PRECISE: clockid_t = 11;
74+
pub const CLOCK_MONOTONIC_FAST: clockid_t = 12;
75+
pub const CLOCK_SECOND: clockid_t = 13;
76+
pub const CLOCK_THREAD_CPUTIME_ID: clockid_t = 14;
77+
pub const CLOCK_PROCESS_CPUTIME_ID: clockid_t = 15;
6578

6679
extern {
6780
pub fn __error() -> *mut ::c_int;
6881

6982
pub fn mprotect(addr: *const ::c_void, len: ::size_t, prot: ::c_int)
7083
-> ::c_int;
7184

72-
pub fn clock_gettime(clk_id: ::c_int, tp: *mut ::timespec) -> ::c_int;
85+
pub fn clock_getres(clk_id: clockid_t, tp: *mut ::timespec) -> ::c_int;
86+
pub fn clock_gettime(clk_id: clockid_t, tp: *mut ::timespec) -> ::c_int;
7387

7488
pub fn posix_fallocate(fd: ::c_int, offset: ::off_t,
7589
len: ::off_t) -> ::c_int;

src/unix/bsd/openbsdlike/mod.rs

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ pub type pthread_key_t = ::c_int;
88
pub type rlim_t = u64;
99
pub type speed_t = ::c_uint;
1010
pub type tcflag_t = ::c_uint;
11+
pub type clockid_t = ::c_int;
1112

1213
pub enum timezone {}
1314

@@ -258,8 +259,16 @@ pub const _SC_XOPEN_SHM : ::c_int = 30;
258259
pub const PTHREAD_CREATE_JOINABLE : ::c_int = 0;
259260
pub const PTHREAD_CREATE_DETACHED : ::c_int = 1;
260261

261-
pub const CLOCK_REALTIME : ::c_int = 0;
262-
pub const CLOCK_MONOTONIC : ::c_int = 3;
262+
// http://man.openbsd.org/OpenBSD-current/man2/clock_getres.2
263+
// The man page says clock_gettime(3) can accept various values as clockid_t but
264+
// http://fxr.watson.org/fxr/source/kern/kern_time.c?v=OPENBSD;im=excerpts#L161
265+
// the implementation rejects anything other than the below two
266+
//
267+
// http://netbsd.gw.com/cgi-bin/man-cgi?clock_gettime
268+
// https://github.com/jsonn/src/blob/HEAD/sys/kern/subr_time.c#L222
269+
// Basically the same goes for NetBSD
270+
pub const CLOCK_REALTIME: clockid_t = 0;
271+
pub const CLOCK_MONOTONIC: clockid_t = 3;
263272

264273
pub const RLIMIT_CPU: ::c_int = 0;
265274
pub const RLIMIT_FSIZE: ::c_int = 1;
@@ -380,8 +389,10 @@ pub const RTLD_GLOBAL: ::c_int = 0x100;
380389
extern {
381390
pub fn mincore(addr: *mut ::c_void, len: ::size_t,
382391
vec: *mut ::c_char) -> ::c_int;
392+
#[cfg_attr(target_os = "netbsd", link_name = "__clock_getres50")]
393+
pub fn clock_getres(clk_id: clockid_t, tp: *mut ::timespec) -> ::c_int;
383394
#[cfg_attr(target_os = "netbsd", link_name = "__clock_gettime50")]
384-
pub fn clock_gettime(clk_id: ::c_int, tp: *mut ::timespec) -> ::c_int;
395+
pub fn clock_gettime(clk_id: clockid_t, tp: *mut ::timespec) -> ::c_int;
385396
pub fn __errno() -> *mut ::c_int;
386397
pub fn shm_open(name: *const ::c_char, oflag: ::c_int, mode: ::mode_t)
387398
-> ::c_int;

src/unix/notbsd/linux/musl/mod.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,11 @@ pub const TIOCINQ: ::c_ulong = ::FIONREAD;
148148
pub const RTLD_GLOBAL: ::c_int = 0x100;
149149
pub const RTLD_NOLOAD: ::c_int = 0x4;
150150

151+
// TODO(#247) Temporarily musl-specific (available since musl 0.9.12 / Linux
152+
// kernel 3.10). See also notbsd/mod.rs
153+
pub const CLOCK_SGI_CYCLE: ::clockid_t = 10;
154+
pub const CLOCK_TAI: ::clockid_t = 11;
155+
151156
extern {
152157
pub fn getnameinfo(sa: *const ::sockaddr,
153158
salen: ::socklen_t,

src/unix/notbsd/mod.rs

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ pub type pthread_key_t = ::c_uint;
55
pub type speed_t = ::c_uint;
66
pub type tcflag_t = ::c_uint;
77
pub type loff_t = ::c_longlong;
8+
pub type clockid_t = ::c_int;
89

910
pub enum timezone {}
1011

@@ -203,8 +204,20 @@ pub const SIGTRAP: ::c_int = 5;
203204
pub const PTHREAD_CREATE_JOINABLE: ::c_int = 0;
204205
pub const PTHREAD_CREATE_DETACHED: ::c_int = 1;
205206

206-
pub const CLOCK_REALTIME: ::c_int = 0;
207-
pub const CLOCK_MONOTONIC: ::c_int = 1;
207+
pub const CLOCK_REALTIME: clockid_t = 0;
208+
pub const CLOCK_MONOTONIC: clockid_t = 1;
209+
pub const CLOCK_PROCESS_CPUTIME_ID: clockid_t = 2;
210+
pub const CLOCK_THREAD_CPUTIME_ID: clockid_t = 3;
211+
pub const CLOCK_MONOTONIC_RAW: clockid_t = 4;
212+
pub const CLOCK_REALTIME_COARSE: clockid_t = 5;
213+
pub const CLOCK_MONOTONIC_COARSE: clockid_t = 6;
214+
pub const CLOCK_BOOTTIME: clockid_t = 7;
215+
pub const CLOCK_REALTIME_ALARM: clockid_t = 8;
216+
pub const CLOCK_BOOTTIME_ALARM: clockid_t = 9;
217+
// TODO(#247) Someday our Travis shall have glibc 2.21 (released in Sep
218+
// 2014.) See also musl/mod.rs
219+
// pub const CLOCK_SGI_CYCLE: clockid_t = 10;
220+
// pub const CLOCK_TAI: clockid_t = 11;
208221

209222
pub const RLIMIT_CPU: ::c_int = 0;
210223
pub const RLIMIT_FSIZE: ::c_int = 1;
@@ -666,7 +679,8 @@ extern {
666679
pub fn fdatasync(fd: ::c_int) -> ::c_int;
667680
pub fn mincore(addr: *mut ::c_void, len: ::size_t,
668681
vec: *mut ::c_uchar) -> ::c_int;
669-
pub fn clock_gettime(clk_id: ::c_int, tp: *mut ::timespec) -> ::c_int;
682+
pub fn clock_getres(clk_id: clockid_t, tp: *mut ::timespec) -> ::c_int;
683+
pub fn clock_gettime(clk_id: clockid_t, tp: *mut ::timespec) -> ::c_int;
670684
pub fn prctl(option: ::c_int, ...) -> ::c_int;
671685
pub fn pthread_getattr_np(native: ::pthread_t,
672686
attr: *mut ::pthread_attr_t) -> ::c_int;

src/unix/solaris/mod.rs

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
pub type c_char = i8;
22
pub type c_long = i64;
33
pub type c_ulong = u64;
4+
pub type clockid_t = ::c_int;
45

56
pub type blkcnt_t = i64;
67
pub type clock_t = i64;
@@ -540,8 +541,18 @@ pub const PTHREAD_STACK_MIN: ::size_t = 4096;
540541

541542
pub const SIGSTKSZ: ::size_t = 8192;
542543

543-
pub const CLOCK_REALTIME: ::c_int = 3;
544-
pub const CLOCK_MONOTONIC: ::c_int = 4;
544+
// https://illumos.org/man/3c/clock_gettime
545+
// https://github.com/illumos/illumos-gate/
546+
// blob/HEAD/usr/src/lib/libc/amd64/sys/__clock_gettime.s
547+
// clock_gettime(3c) doesn't seem to accept anything other than CLOCK_REALTIME
548+
// or __CLOCK_REALTIME0
549+
//
550+
// https://github.com/illumos/illumos-gate/
551+
// blob/HEAD/usr/src/uts/common/sys/time_impl.h
552+
// Confusing! CLOCK_HIGHRES==CLOCK_MONOTONIC==4
553+
// __CLOCK_REALTIME0==0 is an obsoleted version of CLOCK_REALTIME==3
554+
pub const CLOCK_REALTIME: clockid_t = 3;
555+
pub const CLOCK_MONOTONIC: clockid_t = 4;
545556

546557
pub const RLIMIT_CPU: ::c_int = 0;
547558
pub const RLIMIT_FSIZE: ::c_int = 1;
@@ -752,7 +763,8 @@ extern {
752763
pub fn ioctl(fildes: ::c_int, request: ::c_int, ...) -> ::c_int;
753764
pub fn mprotect(addr: *const ::c_void, len: ::size_t, prot: ::c_int)
754765
-> ::c_int;
755-
pub fn clock_gettime(clk_id: ::c_int, tp: *mut ::timespec) -> ::c_int;
766+
pub fn clock_getres(clk_id: clockid_t, tp: *mut ::timespec) -> ::c_int;
767+
pub fn clock_gettime(clk_id: clockid_t, tp: *mut ::timespec) -> ::c_int;
756768
pub fn getnameinfo(sa: *const ::sockaddr,
757769
salen: ::socklen_t,
758770
host: *mut ::c_char,

0 commit comments

Comments
 (0)