Reid Spencer | 9926c31 | 2004-09-24 23:25:19 +0000 | [diff] [blame] | 1 | //===- Linux/TimeValue.cpp - Linux TimeValue Implementation -----*- C++ -*-===// |
| 2 | // |
| 3 | // The LLVM Compiler Infrastructure |
| 4 | // |
| 5 | // This file was developed by Reid Spencer and is distributed under the |
| 6 | // University of Illinois Open Source License. See LICENSE.TXT for details. |
| 7 | // |
| 8 | //===----------------------------------------------------------------------===// |
| 9 | // |
| 10 | // This file provides the Linux specific implementation of the TimeValue class. |
| 11 | // |
| 12 | //===----------------------------------------------------------------------===// |
| 13 | |
| 14 | // Include the generic Unix implementation |
Reid Spencer | fb9aac8 | 2004-11-14 22:07:04 +0000 | [diff] [blame^] | 15 | #include "../Unix/TimeValue.cpp" |
| 16 | |
Reid Spencer | 9926c31 | 2004-09-24 23:25:19 +0000 | [diff] [blame] | 17 | #include <sys/time.h> |
| 18 | |
| 19 | namespace llvm { |
Reid Spencer | fb9aac8 | 2004-11-14 22:07:04 +0000 | [diff] [blame^] | 20 | |
Reid Spencer | 9926c31 | 2004-09-24 23:25:19 +0000 | [diff] [blame] | 21 | using namespace sys; |
| 22 | |
| 23 | //===----------------------------------------------------------------------===// |
| 24 | //=== WARNING: Implementation here must contain only Linux specific code |
| 25 | //=== and must not be generic UNIX code (see ../Unix/TimeValue.cpp) |
| 26 | //===----------------------------------------------------------------------===// |
| 27 | |
Reid Spencer | 725f2c8 | 2004-09-25 08:32:37 +0000 | [diff] [blame] | 28 | TimeValue TimeValue::now() { |
Reid Spencer | 9926c31 | 2004-09-24 23:25:19 +0000 | [diff] [blame] | 29 | struct timeval the_time; |
| 30 | timerclear(&the_time); |
| 31 | if (0 != ::gettimeofday(&the_time,0)) |
| 32 | ThrowErrno("Couldn't obtain time of day"); |
| 33 | |
Reid Spencer | 725f2c8 | 2004-09-25 08:32:37 +0000 | [diff] [blame] | 34 | return TimeValue( |
| 35 | static_cast<TimeValue::SecondsType>( the_time.tv_sec ), |
| 36 | static_cast<TimeValue::NanoSecondsType>( the_time.tv_usec * |
| 37 | NANOSECONDS_PER_MICROSECOND ) ); |
Reid Spencer | 9926c31 | 2004-09-24 23:25:19 +0000 | [diff] [blame] | 38 | } |
| 39 | // vim: sw=2 smartindent smarttab tw=80 autoindent expandtab |
| 40 | |
| 41 | } |