From bfb7b3eb6822e790b660ce2b4410e777963636c2 Mon Sep 17 00:00:00 2001 From: Reid Spencer Date: Mon, 15 Nov 2004 04:36:35 +0000 Subject: Consolidate the implementation of TimeValue::now() for Unix to use the seemingly ubiquitous gettimeofday(3) call. llvm-svn: 17813 --- llvm/lib/System/Unix/TimeValue.cpp | 13 +++++++++++++ 1 file changed, 13 insertions(+) (limited to 'llvm/lib/System/Unix/TimeValue.cpp') 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 +#include 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( the_time.tv_sec ), + static_cast( the_time.tv_usec * + NANOSECONDS_PER_MICROSECOND ) ); +} + } // vim: sw=2 smartindent smarttab tw=80 autoindent expandtab -- cgit v1.2.3