about summary refs log tree commit diff
path: root/src/libstd/sys/unix/time.rs
AgeCommit message (Collapse)AuthorLines
2020-07-27mv std libs to library/mark-352/+0
2020-02-02Strip unnecessary subexpressionFriedrich von Never-1/+0
It became unnecessary since a06baa56b95674fc626b3c3fd680d6a65357fe60 reformatted the file.
2019-12-22Format the worldMark Rousskov-81/+43
2019-10-06redesign of the interface to the unikernel HermitCoreStefan Lankes-2/+2
- the old interface between HermitCore and the Rust Standard Library based on a small C library (newlib) - remove this interface and call directly the unikernel - remove the dependency to the HermitCore linker - use rust-lld as linker
2019-09-05Add Fuchsia to actually_monotonicTaylor Cramer-0/+1
Fuchsia provides a fully monotonic clock.
2019-08-01Remove mach dependencygnzlbg-5/+21
2019-08-01Update libc and use the Mach kernel APIs via the mach crate instead.gnzlbg-4/+5
2019-04-04std: Avoid usage of `Once` in `Instant`Alex Crichton-7/+20
This commit removes usage of `Once` from the internal implementation of time utilities on OSX and Windows. It turns out that we accidentally hit a deadlock today (#59020) via events that look like: * A thread invokes `park_timeout` * Internally, only on OSX, `park_timeout` calls `Instant::elapsed` * Inside of `Instant::elapsed` on OSX we enter a `Once` to initialize global timer data * Inside of `Once`, it attempts to `park` This means on the same stack frame, when there's contention, we're calling `park` from inside `park_timeout`, causing a deadlock! The solution implemented in this commit was to remove usage of `Once` and instead just do a small dance with atomics. There's no real need we need to guarantee that the global information is only learned once, only that it's only *stored* once. This implementation may have multiple threads invoke `mach_timebase_info`, but only one will store the global information which will amortize the cost for all other threads. A similar fix has been applied to windows to be uniform across our implementations, but looking at the code on Windows no deadlock was possible. This is purely just a consistency update for Windows and in theory a slightly leaner implementation. Closes #59020
2019-03-31libstd: deny(elided_lifetimes_in_paths)Mazdak Farrokhzad-3/+3
2019-03-22Update sys::time impls to have checked_sub_instantLinus Färnstrand-8/+5
2019-02-28libstd => 2018Taiki Endo-15/+13
2019-01-07std: Force `Instant::now()` to be monotonicAlex Crichton-12/+28
This commit is an attempt to force `Instant::now` to be monotonic through any means possible. We tried relying on OS/hardware/clock implementations, but those seem buggy enough that we can't rely on them in practice. This commit implements the same hammer Firefox recently implemented (noted in #56612) which is to just keep whatever the lastest `Instant::now()` return value was in memory, returning that instead of the OS looks like it's moving backwards. Closes #48514 Closes #49281 cc #51648 cc #56560 Closes #56612 Closes #56940
2018-12-25Remove licensesMark Rousskov-10/+0
2018-12-13Add checked_sub for Instant and SystemTimeLinus Färnstrand-27/+21
2018-12-13Add checked_add method to Instant time typeLinus Färnstrand-23/+13
2018-11-25Auto merge of #55527 - sgeisler:time-checked-add, r=sfacklerbors-6/+16
Implement checked_add_duration for SystemTime [Original discussion on the rust user forum](https://users.rust-lang.org/t/std-systemtime-misses-a-checked-add-function/21785) Since `SystemTime` is opaque there is no way to check if the result of an addition will be in bounds. That makes the `Add<Duration>` trait completely unusable with untrusted data. This is a big problem because adding a `Duration` to `UNIX_EPOCH` is the standard way of constructing a `SystemTime` from a unix timestamp. This PR implements `checked_add_duration(&self, &Duration) -> Option<SystemTime>` for `std::time::SystemTime` and as a prerequisite also for all platform specific time structs. This also led to the refactoring of many `add_duration(&self, &Duration) -> SystemTime` functions to avoid redundancy (they now unwrap the result of `checked_add_duration`). Some basic unit tests for the newly introduced function were added too. I wasn't sure which stabilization attribute to add to the newly introduced function, so I just chose `#[stable(feature = "time_checked_add", since = "1.32.0")]` for now to make it compile. Please let me know how I should change it or if I violated any other conventions. P.S.: I could only test on Linux so far, so I don't necessarily expect it to compile for all platforms.
2018-11-15use ? operator instead of matchSebastian Geisler-10/+3
2018-11-15Implement checked_add_duration for SystemTimeSebastian Geisler-6/+23
Since SystemTime is opaque there is no way to check if the result of an addition will be in bounds. That makes the Add<Duration> trait completely unusable with untrusted data. This is a big problem because adding a Duration to UNIX_EPOCH is the standard way of constructing a SystemTime from a unix timestamp. This commit implements checked_add_duration(&self, &Duration) -> Option<SystemTime> for std::time::SystemTime and as a prerequisite also for all platform specific time structs. This also led to the refactoring of many add_duration(&self, &Duration) -> SystemTime functions to avoid redundancy (they now unwrap the result of checked_add_duration). Some basic unit tests for the newly introduced function were added too.
2018-11-06refactor: use shorthand fieldsteresy-2/+2
2018-07-30Add targets for HermitCore (https://hermitcore.org) to the Rust compiler and ↵Colin Finck-2/+2
port libstd to it. As a start, the port uses the simplest possible configuration (no jemalloc, abort on panic) and makes use of existing Unix-specific code wherever possible. It adds targets for x86_64 (current main HermitCore platform) and aarch64 (HermitCore platform under development). Together with the patches to "liblibc" and "llvm", this enables HermitCore applications to be written in Rust.
2018-06-04Clarify error phrase in `sub_instant` functionClaudio Bley-1/+1
Uses the same wording as [`src/libstd/sys/windows/time.rs`][1]. 1: https://github.com/avdv/rust/blob/95e2bf253d864c5e14ad000ffa2040ce85916056/src/libstd/sys/windows/time.rs#L65
2018-05-31Fix confusing error message for sub_instantClaudio Bley-1/+1
When subtracting an Instant from another, the function will panick when `RHS > self`, but the error message confusingly displays a different error: ```rust let i = Instant::now(); let other = Instant::now(); if other > i { println!("{:?}", i - other); } ``` This results in a panic: ``` thread 'test_instant' panicked at 'other was less than the current instant', libstd/sys/unix/time.rs:292:17 ```
2017-12-19Add Hash impl for SystemTime and InstantVitaly _Vi Shukela-4/+12
Closes #46670.
2017-10-20Fix some tests for linux gnux32Marco A L Barbosa-2/+2
2017-09-07Properly detect overflow in Instance +/- Duration.kennytm-7/+15
Avoid unchecked cast from `u64` to `i64`. Use `try_into()` for checked cast. (On Unix, cast to `time_t` instead of `i64`.)
2017-04-25Fix a copy-paste error in `Instant::sub_duration`Tobias Bucher-1/+1
Fixes #41514.
2016-07-12Use `ptr::{null, null_mut}` instead of `0 as *{const, mut}`Tobias Bucher-2/+4
2016-05-24std: Stabilize APIs for the 1.10 releaseAlex Crichton-188/+130
This commit applies the FCP decisions made by the libs team for the 1.10 cycle, including both new stabilizations and deprecations. Specifically, the list of APIs is: Stabilized: * `os::windows::fs::OpenOptionsExt::access_mode` * `os::windows::fs::OpenOptionsExt::share_mode` * `os::windows::fs::OpenOptionsExt::custom_flags` * `os::windows::fs::OpenOptionsExt::attributes` * `os::windows::fs::OpenOptionsExt::security_qos_flags` * `os::unix::fs::OpenOptionsExt::custom_flags` * `sync::Weak::new` * `Default for sync::Weak` * `panic::set_hook` * `panic::take_hook` * `panic::PanicInfo` * `panic::PanicInfo::payload` * `panic::PanicInfo::location` * `panic::Location` * `panic::Location::file` * `panic::Location::line` * `ffi::CStr::from_bytes_with_nul` * `ffi::CStr::from_bytes_with_nul_unchecked` * `ffi::FromBytesWithNulError` * `fs::Metadata::modified` * `fs::Metadata::accessed` * `fs::Metadata::created` * `sync::atomic::Atomic{Usize,Isize,Bool,Ptr}::compare_exchange` * `sync::atomic::Atomic{Usize,Isize,Bool,Ptr}::compare_exchange_weak` * `collections::{btree,hash}_map::{Occupied,Vacant,}Entry::key` * `os::unix::net::{UnixStream, UnixListener, UnixDatagram, SocketAddr}` * `SocketAddr::is_unnamed` * `SocketAddr::as_pathname` * `UnixStream::connect` * `UnixStream::pair` * `UnixStream::try_clone` * `UnixStream::local_addr` * `UnixStream::peer_addr` * `UnixStream::set_read_timeout` * `UnixStream::set_write_timeout` * `UnixStream::read_timeout` * `UnixStream::write_Timeout` * `UnixStream::set_nonblocking` * `UnixStream::take_error` * `UnixStream::shutdown` * Read/Write/RawFd impls for `UnixStream` * `UnixListener::bind` * `UnixListener::accept` * `UnixListener::try_clone` * `UnixListener::local_addr` * `UnixListener::set_nonblocking` * `UnixListener::take_error` * `UnixListener::incoming` * RawFd impls for `UnixListener` * `UnixDatagram::bind` * `UnixDatagram::unbound` * `UnixDatagram::pair` * `UnixDatagram::connect` * `UnixDatagram::try_clone` * `UnixDatagram::local_addr` * `UnixDatagram::peer_addr` * `UnixDatagram::recv_from` * `UnixDatagram::recv` * `UnixDatagram::send_to` * `UnixDatagram::send` * `UnixDatagram::set_read_timeout` * `UnixDatagram::set_write_timeout` * `UnixDatagram::read_timeout` * `UnixDatagram::write_timeout` * `UnixDatagram::set_nonblocking` * `UnixDatagram::take_error` * `UnixDatagram::shutdown` * RawFd impls for `UnixDatagram` * `{BTree,Hash}Map::values_mut` * `<[_]>::binary_search_by_key` Deprecated: * `StaticCondvar` - this, and all other static synchronization primitives below, are usable today through the lazy-static crate on stable Rust today. Additionally, we'd like the non-static versions to be directly usable in a static context one day, so they're unlikely to be the final forms of the APIs in any case. * `CONDVAR_INIT` * `StaticMutex` * `MUTEX_INIT` * `StaticRwLock` * `RWLOCK_INIT` * `iter::Peekable::is_empty` Closes #27717 Closes #27720 cc #27784 (but encode methods still exist) Closes #30014 Closes #30425 Closes #30449 Closes #31190 Closes #31399 Closes #31767 Closes #32111 Closes #32281 Closes #32312 Closes #32551 Closes #33018
2016-04-07Fix libstd on DragonFlyMichael Neumann-1/+6
Following changes: * birthtime does not exist on DragonFly * errno: __dfly_error is no more. Use #[thread_local] static errno. * clock_gettime expects a c_ulong (use a type alias) These changes are required to build DragonFly snapshots again.
2016-03-15std: Fix overflow when subtracting InstantAlex Crichton-4/+4
This code was currently only exercised on OSX, but this applies the same method of subtraction used on Linux which doesn't have the same overflow issues. Note that this currently includes no tests, but that's because this is only visible with debug assertions enabled. Soon, however, I'll enable debug assertions on all auto builds on the bots so we should get testing for this. Closes #32268
2016-02-04std: Expose SystemTime accessors on fs::MetadataAlex Crichton-0/+12
These accessors are used to get at the last modification, last access, and creation time of the underlying file. Currently not all platforms provide the creation time, so that currently returns `Option`.
2015-12-04Fix the time overflow on mac as wellSean Griffin-1/+1
2015-12-02Ensure two `SystemTime`s are equal when nanos add to exactly 1BSean Griffin-1/+1
Currently if you add a duration which should lead to 0 nanos and 1 additional second, we end up with no additional seconds, and 1000000000 nanos.
2015-11-19std: Add Instant and SystemTime to std::timeAlex Crichton-55/+326
This commit is an implementation of [RFC 1288][rfc] which adds two new unstable types to the `std::time` module. The `Instant` type is used to represent measurements of a monotonically increasing clock suitable for measuring time withing a process for operations such as benchmarks or just the elapsed time to do something. An `Instant` favors panicking when bugs are found as the bugs are programmer errors rather than typical errors that can be encountered. [rfc]: https://github.com/rust-lang/rfcs/pull/1288 The `SystemTime` type is used to represent a system timestamp and is not monotonic. Very few guarantees are provided about this measurement of the system clock, but a fixed point in time (`UNIX_EPOCH`) is provided to learn about the relative distance from this point for any particular time stamp. This PR takes the same implementation strategy as the `time` crate on crates.io, namely: | Platform | Instant | SystemTime | |------------|--------------------------|--------------------------| | Windows | QueryPerformanceCounter | GetSystemTimeAsFileTime | | OSX | mach_absolute_time | gettimeofday | | Unix | CLOCK_MONOTONIC | CLOCK_REALTIME | These implementations can perhaps be refined over time, but they currently satisfy the requirements of the `Instant` and `SystemTime` types while also being portable across implementations and revisions of each platform.
2015-11-18Fix buildbot failuresVadim Petrochenkov-0/+1
2015-11-18Add missing annotations and some testsVadim Petrochenkov-0/+1
2015-11-09std: Migrate to the new libcAlex Crichton-13/+4
* Delete `sys::unix::{c, sync}` as these are now all folded into libc itself * Update all references to use `libc` as a result. * Update all references to the new flat namespace. * Moves all windows bindings into sys::c
2015-10-28Port the standard crates to PNaCl/NaCl.Richard Diamond-3/+3
2015-09-21Various fixes for NetBSD/amd64Sebastian Wicki-0/+2
2015-07-01Add netbsd amd64 supportAlex Newman-0/+1
2015-05-27Use `const fn` to abstract away the contents of UnsafeCell & friends.Eduard Burtescu-2/+2
2015-05-13std: Redesign Duration, implementing RFC 1040Alex Crichton-18/+12
This commit is an implementation of [RFC 1040][rfc] which is a redesign of the currently-unstable `Duration` type. The API of the type has been scaled back to be more conservative and it also no longer supports negative durations. [rfc]: https://github.com/rust-lang/rfcs/blob/master/text/1040-duration-reform.md The inner `duration` module of the `time` module has now been hidden (as `Duration` is reexported) and the feature name for this type has changed from `std_misc` to `duration`. All APIs accepting durations have also been audited to take a more flavorful feature name instead of `std_misc`. Closes #24874
2015-04-27std: Prepare for linking to muslAlex Crichton-1/+2
This commit modifies the standard library and its dependencies to link correctly when built against MUSL. This primarily ensures that the right libraries are linked against and when they're linked against they're linked against statically.
2015-03-12std: Remove #[allow] directives in sys modulesAlex Crichton-5/+3
These were suppressing lots of interesting warnings! Turns out there was also quite a bit of dead code.
2015-02-11fixing trailing whitespace errorsDave Huseby-1/+1
2015-02-11bitrig integrationDave Huseby-1/+4
2015-02-01openbsd supportSébastien Marie-1/+2
2015-01-16Rewrite Condvar::wait_timeout and make it publicSteven Fackler-0/+124
**The implementation is a direct adaptation of libcxx's condition_variable implementation.** pthread_cond_timedwait uses the non-monotonic system clock. It's possible to change the clock to a monotonic via pthread_cond_attr, but this is incompatible with static initialization. To deal with this, we calculate the timeout using the system clock, and maintain a separate record of the start and end times with a monotonic clock to be used for calculation of the return value.