diff options
author | Reid Spencer <rspencer@reidspencer.com> | 2004-11-15 04:36:35 +0000 |
---|---|---|
committer | Reid Spencer <rspencer@reidspencer.com> | 2004-11-15 04:36:35 +0000 |
commit | bfb7b3eb6822e790b660ce2b4410e777963636c2 (patch) | |
tree | 1586536d96d5c3fab405ea0f435990993871d2f0 /llvm/lib/System/Unix/TimeValue.cpp | |
parent | cbd9aeb5876b97711910f5450bb30e5fca79cc56 (diff) | |
download | bcm5719-llvm-bfb7b3eb6822e790b660ce2b4410e777963636c2.tar.gz bcm5719-llvm-bfb7b3eb6822e790b660ce2b4410e777963636c2.zip |
Consolidate the implementation of TimeValue::now() for Unix to use the
seemingly ubiquitous gettimeofday(3) call.
llvm-svn: 17813
Diffstat (limited to 'llvm/lib/System/Unix/TimeValue.cpp')
-rw-r--r-- | llvm/lib/System/Unix/TimeValue.cpp | 13 |
1 files changed, 13 insertions, 0 deletions
diff --git a/llvm/lib/System/Unix/TimeValue.cpp b/llvm/lib/System/Unix/TimeValue.cpp index f029f8dadca..6b476c86cad 100644 --- a/llvm/lib/System/Unix/TimeValue.cpp +++ b/llvm/lib/System/Unix/TimeValue.cpp @@ -19,6 +19,7 @@ #include "Unix.h" #include <time.h> +#include <sys/time.h> namespace llvm { using namespace sys; @@ -34,5 +35,17 @@ std::string TimeValue::toString() { return result.substr(0,24); } +TimeValue TimeValue::now() { + struct timeval the_time; + ::timerclear(&the_time); + if (0 != ::gettimeofday(&the_time,0)) + ThrowErrno("Couldn't obtain time of day"); + + return TimeValue( + static_cast<TimeValue::SecondsType>( the_time.tv_sec ), + static_cast<TimeValue::NanoSecondsType>( the_time.tv_usec * + NANOSECONDS_PER_MICROSECOND ) ); +} + } // vim: sw=2 smartindent smarttab tw=80 autoindent expandtab |