diff options
author | Niall Douglas (s [underscore] sourceforge {at} nedprod [dot] com) <spamtrap@nedprod.com> | 2020-10-06 17:57:42 +0300 |
---|---|---|
committer | Niall Douglas (s [underscore] sourceforge {at} nedprod [dot] com) <spamtrap@nedprod.com> | 2020-10-06 17:57:42 +0300 |
commit | e8f25ff3646124c4090a3413bfb43751b680a3ff (patch) | |
tree | 0322126bfd07a48f91ea05862244123194ba098c | |
parent | b8dcd691aea2b40f6b29f15f3600dbbbca034a57 (diff) | |
parent | 902ce7230a5c27162dfa28e9a02a3d2930e8e602 (diff) |
Merge branch 'develop' of github.com:ned14/llfio into develop
-rw-r--r-- | include/llfio/v2.0/deadline.h | 125 | ||||
-rw-r--r-- | include/llfio/v2.0/detail/impl/posix/import.hpp | 4 | ||||
-rw-r--r-- | include/llfio/v2.0/detail/impl/windows/import.hpp | 4 |
3 files changed, 79 insertions, 54 deletions
diff --git a/include/llfio/v2.0/deadline.h b/include/llfio/v2.0/deadline.h index 40dde5af..e49f0ce2 100644 --- a/include/llfio/v2.0/deadline.h +++ b/include/llfio/v2.0/deadline.h @@ -49,7 +49,8 @@ struct LLFIO_DEADLINE_NAME { //! True if deadline does not change with system clock changes bool steady; // NOLINT - union { + union + { //! System time from timespec_get(&ts, TIME_UTC) struct timespec utc; // NOLINT //! Nanosecond ticks from start of operation @@ -108,63 +109,87 @@ struct LLFIO_DEADLINE_NAME - began_steady: Set to the steady clock at the beginning of a sleep */ -#define LLFIO_DEADLINE_TO_SLEEP_INIT(d) \ - std::chrono::steady_clock::time_point began_steady; \ - if(d) \ - { \ - if((d).steady && (d).nsecs != 0) \ - began_steady = std::chrono::steady_clock::now(); \ +#define LLFIO_DEADLINE_TO_SLEEP_INIT(d) \ + std::chrono::steady_clock::time_point began_steady; \ + if(d) \ + { \ + if((d).steady && (d).nsecs != 0) \ + began_steady = std::chrono::steady_clock::now(); \ } //! Run inside a series of steps to create a sub-deadline from a master deadline -#define LLFIO_DEADLINE_TO_PARTIAL_DEADLINE(nd, d) \ - if(d) \ - { \ - if((d).steady) \ - { \ - (nd).steady = true; \ - std::chrono::nanoseconds ns = ((d).nsecs != 0) ? std::chrono::duration_cast<std::chrono::nanoseconds>((began_steady + std::chrono::nanoseconds((d).nsecs)) - std::chrono::steady_clock::now()) : std::chrono::nanoseconds(0); \ - if(ns.count() < 0) \ - (nd).nsecs = 0; \ - else \ - (nd).nsecs = ns.count(); \ - } \ - else \ - (nd) = (d); \ +#define LLFIO_DEADLINE_TO_PARTIAL_DEADLINE(nd, d) \ + if(d) \ + { \ + if((d).steady) \ + { \ + (nd).steady = true; \ + std::chrono::nanoseconds ns = \ + ((d).nsecs != 0) ? \ + std::chrono::duration_cast<std::chrono::nanoseconds>((began_steady + std::chrono::nanoseconds((d).nsecs)) - std::chrono::steady_clock::now()) : \ + std::chrono::nanoseconds(0); \ + if(ns.count() < 0) \ + (nd).nsecs = 0; \ + else \ + (nd).nsecs = ns.count(); \ + } \ + else \ + (nd) = (d); \ + } + +//! Run inside a series of steps to create a relative timeout from now from a master deadline +#define LLFIO_DEADLINE_TO_PARTIAL_TIMEOUT(timeout, d) \ + { \ + using timeout_type = std::decay_t<decltype(timeout)>; \ + timeout = timeout_type(); \ + if(d) \ + { \ + if((d).steady) \ + { \ + timeout = ((d).nsecs != 0) ? \ + std::chrono::duration_cast<timeout_type>((began_steady + std::chrono::nanoseconds((d).nsecs)) - std::chrono::steady_clock::now()) : \ + timeout_type(0); \ + } \ + else \ + timeout = std::chrono::duration_cast<timeout_type>(d.as_timepoint() - std::chrono::system_clock::now()); \ + if(timeout.count() < 0) \ + timeout = timeout_type(0); \ + } \ } //! Run inside a loop to detect if the operation has timed out. -#define LLFIO_DEADLINE_TO_TIMEOUT_LOOP(d) \ - if(d) \ - { \ - if((d).steady) \ - { \ - if((d).nsecs == 0 || std::chrono::steady_clock::now() >= (began_steady + std::chrono::nanoseconds((d).nsecs))) \ - return errc::timed_out; \ - } \ - else \ - { \ - LLFIO_V2_NAMESPACE::deadline now(std::chrono::system_clock::now()); \ - if(now.utc.tv_sec > (d).utc.tv_sec || (now.utc.tv_sec == (d).utc.tv_sec && now.utc.tv_nsec >= (d).utc.tv_nsec)) \ - return errc::timed_out; \ - } \ +#define LLFIO_DEADLINE_TO_TIMEOUT_LOOP(d) \ + if(d) \ + { \ + if((d).steady) \ + { \ + if((d).nsecs == 0 || std::chrono::steady_clock::now() >= (began_steady + std::chrono::nanoseconds((d).nsecs))) \ + return LLFIO_V2_NAMESPACE::failure(LLFIO_V2_NAMESPACE::errc::timed_out); \ + } \ + else \ + { \ + LLFIO_V2_NAMESPACE::deadline now(std::chrono::system_clock::now()); \ + if(now.utc.tv_sec > (d).utc.tv_sec || (now.utc.tv_sec == (d).utc.tv_sec && now.utc.tv_nsec >= (d).utc.tv_nsec)) \ + return LLFIO_V2_NAMESPACE::failure(LLFIO_V2_NAMESPACE::errc::timed_out); \ + } \ } -#define LLFIO_DEADLINE_TRY_FOR_UNTIL(name) \ - template <class... Args> bool try_##name (Args && ... args) noexcept \ - { \ - auto r = name(std::forward<Args>(args)..., std::chrono::seconds(0)); \ - return !!r; \ - } \ - template <class... Args, class Rep, class Period> bool try_##name##_for(Args &&... args, const std::chrono::duration<Rep, Period> &duration) noexcept \ - { \ - auto r = name(std::forward<Args>(args)..., duration); \ - return !!r; \ - } \ - template <class... Args, class Clock, class Duration> bool try_##name##_until(Args &&... args, const std::chrono::time_point<Clock, Duration> &timeout) noexcept \ - { \ - auto r = name(std::forward<Args>(args)..., timeout); \ - return !!r; \ +#define LLFIO_DEADLINE_TRY_FOR_UNTIL(name) \ + template <class... Args> bool try_##name(Args &&... args) noexcept \ + { \ + auto r = name(std::forward<Args>(args)..., std::chrono::seconds(0)); \ + return !!r; \ + } \ + template <class... Args, class Rep, class Period> bool try_##name##_for(Args &&... args, const std::chrono::duration<Rep, Period> &duration) noexcept \ + { \ + auto r = name(std::forward<Args>(args)..., duration); \ + return !!r; \ + } \ + template <class... Args, class Clock, class Duration> \ + bool try_##name##_until(Args &&... args, const std::chrono::time_point<Clock, Duration> &timeout) noexcept \ + { \ + auto r = name(std::forward<Args>(args)..., timeout); \ + return !!r; \ } #undef LLFIO_DEADLINE_NAME diff --git a/include/llfio/v2.0/detail/impl/posix/import.hpp b/include/llfio/v2.0/detail/impl/posix/import.hpp index 151bb7f7..753589b9 100644 --- a/include/llfio/v2.0/detail/impl/posix/import.hpp +++ b/include/llfio/v2.0/detail/impl/posix/import.hpp @@ -166,13 +166,13 @@ inline result<int> attribs_from_handle_mode_caching_and_flags(native_handle_type if((d).steady) \ { \ if(std::chrono::steady_clock::now() >= (began_steady + std::chrono::nanoseconds((d).nsecs))) \ - return errc::timed_out; \ + return LLFIO_V2_NAMESPACE::failure(LLFIO_V2_NAMESPACE::errc::timed_out); \ } \ else \ { \ deadline now(std::chrono::system_clock::now()); \ if(now.utc.tv_sec > (d).utc.tv_sec || (now.utc.tv_sec == (d).utc.tv_sec && now.utc.tv_nsec >= (d).utc.tv_nsec)) \ - return errc::timed_out; \ + return LLFIO_V2_NAMESPACE::failure(LLFIO_V2_NAMESPACE::errc::timed_out); \ } \ } diff --git a/include/llfio/v2.0/detail/impl/windows/import.hpp b/include/llfio/v2.0/detail/impl/windows/import.hpp index f2432d02..b1c538c7 100644 --- a/include/llfio/v2.0/detail/impl/windows/import.hpp +++ b/include/llfio/v2.0/detail/impl/windows/import.hpp @@ -1535,12 +1535,12 @@ inline void fill_stat_t(stat_t &stat, LLFIO_POSIX_STAT_STRUCT s, metadata_flags if((d).steady) \ { \ if(std::chrono::steady_clock::now() >= (began_steady + std::chrono::nanoseconds((d).nsecs))) \ - return errc::timed_out; \ + return LLFIO_V2_NAMESPACE::failure(LLFIO_V2_NAMESPACE::errc::timed_out); \ } \ else \ { \ if(std::chrono::system_clock::now() >= end_utc) \ - return errc::timed_out; \ + return LLFIO_V2_NAMESPACE::failure(LLFIO_V2_NAMESPACE::errc::timed_out); \ } \ } |