diff options
author | Pavel Labath <labath@google.com> | 2016-10-24 10:59:17 +0000 |
---|---|---|
committer | Pavel Labath <labath@google.com> | 2016-10-24 10:59:17 +0000 |
commit | 757ca886cd224726d43333d44b5b2ce0989b7f1c (patch) | |
tree | d7416c65b01b7532a708d98fa3ac7a3b2dcab1ce /llvm/lib/Support/Unix/Unix.h | |
parent | 407fd070b776b2c600d53ebb83cb1f4291496606 (diff) | |
download | bcm5719-llvm-757ca886cd224726d43333d44b5b2ce0989b7f1c.tar.gz bcm5719-llvm-757ca886cd224726d43333d44b5b2ce0989b7f1c.zip |
Remove TimeValue usage from llvm/Support
Summary:
This is a follow-up to D25416. It removes all usages of TimeValue from
llvm/Support library (except for the actual TimeValue declaration), and replaces
them with appropriate usages of std::chrono. To facilitate this, I have added
small utility functions for converting time points and durations into appropriate
OS-specific types (FILETIME, struct timespec, ...).
Reviewers: zturner, mehdi_amini
Subscribers: llvm-commits
Differential Revision: https://reviews.llvm.org/D25730
llvm-svn: 284966
Diffstat (limited to 'llvm/lib/Support/Unix/Unix.h')
-rw-r--r-- | llvm/lib/Support/Unix/Unix.h | 36 |
1 files changed, 35 insertions, 1 deletions
diff --git a/llvm/lib/Support/Unix/Unix.h b/llvm/lib/Support/Unix/Unix.h index 97e9cf86d78..239a6d60aae 100644 --- a/llvm/lib/Support/Unix/Unix.h +++ b/llvm/lib/Support/Unix/Unix.h @@ -19,7 +19,8 @@ //=== is guaranteed to work on all UNIX variants. //===----------------------------------------------------------------------===// -#include "llvm/Config/config.h" // Get autoconf configuration settings +#include "llvm/Config/config.h" // Get autoconf configuration settings +#include "llvm/Support/Chrono.h" #include "llvm/Support/Errno.h" #include <algorithm> #include <assert.h> @@ -69,4 +70,37 @@ static inline bool MakeErrMsg( return true; } +namespace llvm { +namespace sys { + +/// Convert a struct timeval to a duration. Note that timeval can be used both +/// as a time point and a duration. Be sure to check what the input represents. +inline std::chrono::microseconds toDuration(const struct timeval &TV) { + return std::chrono::seconds(TV.tv_sec) + + std::chrono::microseconds(TV.tv_usec); +} + +/// Convert a time point to struct timespec. +inline struct timespec toTimeSpec(TimePoint<> TP) { + using namespace std::chrono; + + struct timespec RetVal; + RetVal.tv_sec = toTimeT(TP); + RetVal.tv_nsec = (TP.time_since_epoch() % seconds(1)).count(); + return RetVal; +} + +/// Convert a time point to struct timeval. +inline struct timeval toTimeVal(TimePoint<std::chrono::microseconds> TP) { + using namespace std::chrono; + + struct timeval RetVal; + RetVal.tv_sec = toTimeT(TP); + RetVal.tv_usec = (TP.time_since_epoch() % seconds(1)).count(); + return RetVal; +} + +} // namespace sys +} // namespace llvm + #endif |