LLFIO v2.00
Loading...
Searching...
No Matches
deadline.h File Reference

Provides struct deadline. More...

#include <stdbool.h>
#include <time.h>
#include "config.hpp"
#include <stdexcept>

Classes

struct  llfio_v2_xxx::deadline
 A time deadline in either relative-to-now or absolute (system clock) terms. More...
 

Namespaces

namespace  llfio_v2_xxx
 The LLFIO namespace.
 

Macros

#define LLFIO_DEADLINE_NAME   deadline
 
#define LLFIO_DEADLINE_TO_SLEEP_INIT(d)
 
#define LLFIO_DEADLINE_TO_PARTIAL_DEADLINE(nd, d)
 Run inside a series of steps to create a sub-deadline from a master deadline.
 
#define LLFIO_DEADLINE_TO_PARTIAL_TIMEOUT(timeout, d)
 Run inside a series of steps to create a relative timeout from now from a master deadline.
 
#define LLFIO_DEADLINE_TO_TIMEOUT_LOOP(d)
 Run inside a loop to detect if the operation has timed out.
 
#define LLFIO_DEADLINE_TRY_FOR_UNTIL(name)
 

Detailed Description

Provides struct deadline.

Macro Definition Documentation

◆ LLFIO_DEADLINE_TO_PARTIAL_DEADLINE

#define LLFIO_DEADLINE_TO_PARTIAL_DEADLINE (   nd,
 
)
Value:
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 sub-deadline from a master deadline.

123 { \
124 if((d).steady) \
125 { \
126 (nd).steady = true; \
127 std::chrono::nanoseconds ns = \
128 ((d).nsecs != 0) ? \
129 std::chrono::duration_cast<std::chrono::nanoseconds>((began_steady + std::chrono::nanoseconds((d).nsecs)) - std::chrono::steady_clock::now()) : \
130 std::chrono::nanoseconds(0); \
131 if(ns.count() < 0) \
132 (nd).nsecs = 0; \
133 else \
134 (nd).nsecs = ns.count(); \
135 } \
136 else \
137 (nd) = (d); \
138 }

◆ LLFIO_DEADLINE_TO_PARTIAL_TIMEOUT

#define LLFIO_DEADLINE_TO_PARTIAL_TIMEOUT (   timeout,
 
)
Value:
{ \
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.to_time_point() - std::chrono::system_clock::now()); \
if(timeout.count() < 0) \
timeout = timeout_type(0); \
} \
}

Run inside a series of steps to create a relative timeout from now from a master deadline.

142 { \
143 using timeout_type = std::decay_t<decltype(timeout)>; \
144 timeout = timeout_type(); \
145 if(d) \
146 { \
147 if((d).steady) \
148 { \
149 timeout = ((d).nsecs != 0) ? \
150 std::chrono::duration_cast<timeout_type>((began_steady + std::chrono::nanoseconds((d).nsecs)) - std::chrono::steady_clock::now()) : \
151 timeout_type(0); \
152 } \
153 else \
154 timeout = std::chrono::duration_cast<timeout_type>(d.to_time_point() - std::chrono::system_clock::now()); \
155 if(timeout.count() < 0) \
156 timeout = timeout_type(0); \
157 } \
158 }

◆ LLFIO_DEADLINE_TO_SLEEP_INIT

#define LLFIO_DEADLINE_TO_SLEEP_INIT (   d)
Value:
std::chrono::steady_clock::time_point began_steady; \
if(d) \
{ \
if((d).steady && (d).nsecs != 0) \
began_steady = std::chrono::steady_clock::now(); \
}

Defines a number of variables into its scope:

  • began_steady: Set to the steady clock at the beginning of a sleep
115 { \
116 if((d).steady && (d).nsecs != 0) \
117 began_steady = std::chrono::steady_clock::now(); \
118 }

◆ LLFIO_DEADLINE_TO_TIMEOUT_LOOP

#define LLFIO_DEADLINE_TO_TIMEOUT_LOOP (   d)
Value:
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); \
} \
}

Run inside a loop to detect if the operation has timed out.

163 { \
164 if((d).steady) \
165 { \
166 if((d).nsecs == 0 || std::chrono::steady_clock::now() >= (began_steady + std::chrono::nanoseconds((d).nsecs))) \
167 return LLFIO_V2_NAMESPACE::failure(LLFIO_V2_NAMESPACE::errc::timed_out); \
168 } \
169 else \
170 { \
171 LLFIO_V2_NAMESPACE::deadline now(std::chrono::system_clock::now()); \
172 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)) \
173 return LLFIO_V2_NAMESPACE::failure(LLFIO_V2_NAMESPACE::errc::timed_out); \
174 } \
175 }

◆ LLFIO_DEADLINE_TRY_FOR_UNTIL

#define LLFIO_DEADLINE_TRY_FOR_UNTIL (   name)
Value:
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; \
}
179 { \
180 auto r = name(std::forward<Args>(args)..., std::chrono::seconds(0)); \
181 return !!r; \
182 } \
183 template <class... Args, class Rep, class Period> bool try_##name##_for(Args &&... args, const std::chrono::duration<Rep, Period> &duration) noexcept \
184 { \
185 auto r = name(std::forward<Args>(args)..., duration); \
186 return !!r; \
187 } \
188 template <class... Args, class Clock, class Duration> \
189 bool try_##name##_until(Args &&... args, const std::chrono::time_point<Clock, Duration> &timeout) noexcept \
190 { \
191 auto r = name(std::forward<Args>(args)..., timeout); \
192 return !!r; \
193 }