Skip to content

Commit

Permalink
Auto merge of rust-lang#247 - nodakai:clock_getres, r=alexcrichton
Browse files Browse the repository at this point in the history
Add clock_getres(3) and improve clockid_t constants.

This is still a draft
  • Loading branch information
bors committed Apr 3, 2016
2 parents f288e18 + 7e752a3 commit 331d705
Show file tree
Hide file tree
Showing 6 changed files with 85 additions and 27 deletions.
32 changes: 17 additions & 15 deletions src/unix/bsd/freebsdlike/dragonfly/mod.rs
Expand Up @@ -2,6 +2,7 @@ pub type clock_t = u64;
pub type ino_t = u64;
pub type nlink_t = u32;
pub type blksize_t = i64;
pub type clockid_t = ::c_ulong;

pub type c_long = i64;
pub type c_ulong = u64;
Expand Down Expand Up @@ -96,23 +97,24 @@ pub const RLIM_NLIMITS: ::rlim_t = 12;
pub const Q_GETQUOTA: ::c_int = 0x300;
pub const Q_SETQUOTA: ::c_int = 0x400;

pub const CLOCK_REALTIME: ::c_ulong = 0;
pub const CLOCK_VIRTUAL: ::c_ulong = 1;
pub const CLOCK_PROF: ::c_ulong = 2;
pub const CLOCK_MONOTONIC: ::c_ulong = 4;
pub const CLOCK_UPTIME: ::c_ulong = 5;
pub const CLOCK_UPTIME_PRECISE: ::c_ulong = 7;
pub const CLOCK_UPTIME_FAST: ::c_ulong = 8;
pub const CLOCK_REALTIME_PRECISE: ::c_ulong = 9;
pub const CLOCK_REALTIME_FAST: ::c_ulong = 10;
pub const CLOCK_MONOTONIC_PRECISE: ::c_ulong = 11;
pub const CLOCK_MONOTONIC_FAST: ::c_ulong = 12;
pub const CLOCK_SECOND: ::c_ulong = 13;
pub const CLOCK_THREAD_CPUTIME_ID: ::c_ulong = 14;
pub const CLOCK_PROCESS_CPUTIME_ID: ::c_ulong = 15;
pub const CLOCK_REALTIME: clockid_t = 0;
pub const CLOCK_VIRTUAL: clockid_t = 1;
pub const CLOCK_PROF: clockid_t = 2;
pub const CLOCK_MONOTONIC: clockid_t = 4;
pub const CLOCK_UPTIME: clockid_t = 5;
pub const CLOCK_UPTIME_PRECISE: clockid_t = 7;
pub const CLOCK_UPTIME_FAST: clockid_t = 8;
pub const CLOCK_REALTIME_PRECISE: clockid_t = 9;
pub const CLOCK_REALTIME_FAST: clockid_t = 10;
pub const CLOCK_MONOTONIC_PRECISE: clockid_t = 11;
pub const CLOCK_MONOTONIC_FAST: clockid_t = 12;
pub const CLOCK_SECOND: clockid_t = 13;
pub const CLOCK_THREAD_CPUTIME_ID: clockid_t = 14;
pub const CLOCK_PROCESS_CPUTIME_ID: clockid_t = 15;

extern {
pub fn mprotect(addr: *mut ::c_void, len: ::size_t, prot: ::c_int)
-> ::c_int;
pub fn clock_gettime(clk_id: ::c_ulong, tp: *mut ::timespec) -> ::c_int;
pub fn clock_getres(clk_id: clockid_t, tp: *mut ::timespec) -> ::c_int;
pub fn clock_gettime(clk_id: clockid_t, tp: *mut ::timespec) -> ::c_int;
}
20 changes: 17 additions & 3 deletions src/unix/bsd/freebsdlike/freebsd/mod.rs
Expand Up @@ -3,6 +3,7 @@ pub type clock_t = i32;
pub type ino_t = u32;
pub type nlink_t = u16;
pub type blksize_t = u32;
pub type clockid_t = ::c_int;

pub type fsblkcnt_t = ::uint64_t;
pub type fsfilcnt_t = ::uint64_t;
Expand Down Expand Up @@ -60,16 +61,29 @@ pub const POSIX_FADV_NOREUSE: ::c_int = 5;
pub const MADV_PROTECT: ::c_int = 10;
pub const RUSAGE_THREAD: ::c_int = 1;

pub const CLOCK_REALTIME: ::c_int = 0;
pub const CLOCK_MONOTONIC: ::c_int = 4;
pub const CLOCK_REALTIME: clockid_t = 0;
pub const CLOCK_VIRTUAL: clockid_t = 1;
pub const CLOCK_PROF: clockid_t = 2;
pub const CLOCK_MONOTONIC: clockid_t = 4;
pub const CLOCK_UPTIME: clockid_t = 5;
pub const CLOCK_UPTIME_PRECISE: clockid_t = 7;
pub const CLOCK_UPTIME_FAST: clockid_t = 8;
pub const CLOCK_REALTIME_PRECISE: clockid_t = 9;
pub const CLOCK_REALTIME_FAST: clockid_t = 10;
pub const CLOCK_MONOTONIC_PRECISE: clockid_t = 11;
pub const CLOCK_MONOTONIC_FAST: clockid_t = 12;
pub const CLOCK_SECOND: clockid_t = 13;
pub const CLOCK_THREAD_CPUTIME_ID: clockid_t = 14;
pub const CLOCK_PROCESS_CPUTIME_ID: clockid_t = 15;

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

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

pub fn clock_gettime(clk_id: ::c_int, tp: *mut ::timespec) -> ::c_int;
pub fn clock_getres(clk_id: clockid_t, tp: *mut ::timespec) -> ::c_int;
pub fn clock_gettime(clk_id: clockid_t, tp: *mut ::timespec) -> ::c_int;

pub fn posix_fallocate(fd: ::c_int, offset: ::off_t,
len: ::off_t) -> ::c_int;
Expand Down
17 changes: 14 additions & 3 deletions src/unix/bsd/openbsdlike/mod.rs
Expand Up @@ -8,6 +8,7 @@ pub type pthread_key_t = ::c_int;
pub type rlim_t = u64;
pub type speed_t = ::c_uint;
pub type tcflag_t = ::c_uint;
pub type clockid_t = ::c_int;

pub enum timezone {}

Expand Down Expand Up @@ -258,8 +259,16 @@ pub const _SC_XOPEN_SHM : ::c_int = 30;
pub const PTHREAD_CREATE_JOINABLE : ::c_int = 0;
pub const PTHREAD_CREATE_DETACHED : ::c_int = 1;

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

pub const RLIMIT_CPU: ::c_int = 0;
pub const RLIMIT_FSIZE: ::c_int = 1;
Expand Down Expand Up @@ -380,8 +389,10 @@ pub const RTLD_GLOBAL: ::c_int = 0x100;
extern {
pub fn mincore(addr: *mut ::c_void, len: ::size_t,
vec: *mut ::c_char) -> ::c_int;
#[cfg_attr(target_os = "netbsd", link_name = "__clock_getres50")]
pub fn clock_getres(clk_id: clockid_t, tp: *mut ::timespec) -> ::c_int;
#[cfg_attr(target_os = "netbsd", link_name = "__clock_gettime50")]
pub fn clock_gettime(clk_id: ::c_int, tp: *mut ::timespec) -> ::c_int;
pub fn clock_gettime(clk_id: clockid_t, tp: *mut ::timespec) -> ::c_int;
pub fn __errno() -> *mut ::c_int;
pub fn shm_open(name: *const ::c_char, oflag: ::c_int, mode: ::mode_t)
-> ::c_int;
Expand Down
5 changes: 5 additions & 0 deletions src/unix/notbsd/linux/musl/mod.rs
Expand Up @@ -148,6 +148,11 @@ pub const TIOCINQ: ::c_ulong = ::FIONREAD;
pub const RTLD_GLOBAL: ::c_int = 0x100;
pub const RTLD_NOLOAD: ::c_int = 0x4;

// TODO(#247) Temporarily musl-specific (available since musl 0.9.12 / Linux
// kernel 3.10). See also notbsd/mod.rs
pub const CLOCK_SGI_CYCLE: ::clockid_t = 10;
pub const CLOCK_TAI: ::clockid_t = 11;

extern {
pub fn getnameinfo(sa: *const ::sockaddr,
salen: ::socklen_t,
Expand Down
20 changes: 17 additions & 3 deletions src/unix/notbsd/mod.rs
Expand Up @@ -5,6 +5,7 @@ pub type pthread_key_t = ::c_uint;
pub type speed_t = ::c_uint;
pub type tcflag_t = ::c_uint;
pub type loff_t = ::c_longlong;
pub type clockid_t = ::c_int;

pub enum timezone {}

Expand Down Expand Up @@ -203,8 +204,20 @@ pub const SIGTRAP: ::c_int = 5;
pub const PTHREAD_CREATE_JOINABLE: ::c_int = 0;
pub const PTHREAD_CREATE_DETACHED: ::c_int = 1;

pub const CLOCK_REALTIME: ::c_int = 0;
pub const CLOCK_MONOTONIC: ::c_int = 1;
pub const CLOCK_REALTIME: clockid_t = 0;
pub const CLOCK_MONOTONIC: clockid_t = 1;
pub const CLOCK_PROCESS_CPUTIME_ID: clockid_t = 2;
pub const CLOCK_THREAD_CPUTIME_ID: clockid_t = 3;
pub const CLOCK_MONOTONIC_RAW: clockid_t = 4;
pub const CLOCK_REALTIME_COARSE: clockid_t = 5;
pub const CLOCK_MONOTONIC_COARSE: clockid_t = 6;
pub const CLOCK_BOOTTIME: clockid_t = 7;
pub const CLOCK_REALTIME_ALARM: clockid_t = 8;
pub const CLOCK_BOOTTIME_ALARM: clockid_t = 9;
// TODO(#247) Someday our Travis shall have glibc 2.21 (released in Sep
// 2014.) See also musl/mod.rs
// pub const CLOCK_SGI_CYCLE: clockid_t = 10;
// pub const CLOCK_TAI: clockid_t = 11;

pub const RLIMIT_CPU: ::c_int = 0;
pub const RLIMIT_FSIZE: ::c_int = 1;
Expand Down Expand Up @@ -666,7 +679,8 @@ extern {
pub fn fdatasync(fd: ::c_int) -> ::c_int;
pub fn mincore(addr: *mut ::c_void, len: ::size_t,
vec: *mut ::c_uchar) -> ::c_int;
pub fn clock_gettime(clk_id: ::c_int, tp: *mut ::timespec) -> ::c_int;
pub fn clock_getres(clk_id: clockid_t, tp: *mut ::timespec) -> ::c_int;
pub fn clock_gettime(clk_id: clockid_t, tp: *mut ::timespec) -> ::c_int;
pub fn prctl(option: ::c_int, ...) -> ::c_int;
pub fn pthread_getattr_np(native: ::pthread_t,
attr: *mut ::pthread_attr_t) -> ::c_int;
Expand Down
18 changes: 15 additions & 3 deletions src/unix/solaris/mod.rs
@@ -1,6 +1,7 @@
pub type c_char = i8;
pub type c_long = i64;
pub type c_ulong = u64;
pub type clockid_t = ::c_int;

pub type blkcnt_t = i64;
pub type clock_t = i64;
Expand Down Expand Up @@ -540,8 +541,18 @@ pub const PTHREAD_STACK_MIN: ::size_t = 4096;

pub const SIGSTKSZ: ::size_t = 8192;

pub const CLOCK_REALTIME: ::c_int = 3;
pub const CLOCK_MONOTONIC: ::c_int = 4;
// https://illumos.org/man/3c/clock_gettime
// https://github.com/illumos/illumos-gate/
// blob/HEAD/usr/src/lib/libc/amd64/sys/__clock_gettime.s
// clock_gettime(3c) doesn't seem to accept anything other than CLOCK_REALTIME
// or __CLOCK_REALTIME0
//
// https://github.com/illumos/illumos-gate/
// blob/HEAD/usr/src/uts/common/sys/time_impl.h
// Confusing! CLOCK_HIGHRES==CLOCK_MONOTONIC==4
// __CLOCK_REALTIME0==0 is an obsoleted version of CLOCK_REALTIME==3
pub const CLOCK_REALTIME: clockid_t = 3;
pub const CLOCK_MONOTONIC: clockid_t = 4;

pub const RLIMIT_CPU: ::c_int = 0;
pub const RLIMIT_FSIZE: ::c_int = 1;
Expand Down Expand Up @@ -752,7 +763,8 @@ extern {
pub fn ioctl(fildes: ::c_int, request: ::c_int, ...) -> ::c_int;
pub fn mprotect(addr: *const ::c_void, len: ::size_t, prot: ::c_int)
-> ::c_int;
pub fn clock_gettime(clk_id: ::c_int, tp: *mut ::timespec) -> ::c_int;
pub fn clock_getres(clk_id: clockid_t, tp: *mut ::timespec) -> ::c_int;
pub fn clock_gettime(clk_id: clockid_t, tp: *mut ::timespec) -> ::c_int;
pub fn getnameinfo(sa: *const ::sockaddr,
salen: ::socklen_t,
host: *mut ::c_char,
Expand Down

0 comments on commit 331d705

Please sign in to comment.