Reid Spencer | 0d5716e | 2004-09-25 05:03:54 +0000 | [diff] [blame] | 1 | //===- FreeBSD/TimeValue.cpp - FreeBSD 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 | // |
Reid Spencer | d722bf5 | 2004-09-28 23:54:12 +0000 | [diff] [blame] | 10 | // This file provides the FreeBSD specific implementation of the TimeValue class. |
Reid Spencer | 0d5716e | 2004-09-25 05:03:54 +0000 | [diff] [blame] | 11 | // |
| 12 | //===----------------------------------------------------------------------===// |
| 13 | |
| 14 | // Include the generic Unix implementation |
| 15 | #include "../Unix/Unix.h" |
Reid Spencer | d722bf5 | 2004-09-28 23:54:12 +0000 | [diff] [blame] | 16 | #include <sys/time.h> |
Reid Spencer | 0d5716e | 2004-09-25 05:03:54 +0000 | [diff] [blame] | 17 | |
| 18 | namespace llvm { |
| 19 | using namespace sys; |
| 20 | |
| 21 | //===----------------------------------------------------------------------===// |
| 22 | //=== WARNING: Implementation here must contain only FreeBSD specific code |
| 23 | //=== and must not be generic UNIX code (see ../Unix/TimeValue.cpp) |
| 24 | //===----------------------------------------------------------------------===// |
| 25 | |
Reid Spencer | d722bf5 | 2004-09-28 23:54:12 +0000 | [diff] [blame] | 26 | TimeValue TimeValue::now() { |
| 27 | struct timeval the_time; |
| 28 | timerclear(&the_time); |
| 29 | if (0 != ::gettimeofday(&the_time,0)) |
| 30 | ThrowErrno("Couldn't obtain time of day"); |
Reid Spencer | 0d5716e | 2004-09-25 05:03:54 +0000 | [diff] [blame] | 31 | |
Reid Spencer | d722bf5 | 2004-09-28 23:54:12 +0000 | [diff] [blame] | 32 | return TimeValue( |
| 33 | static_cast<TimeValue::SecondsType>( the_time.tv_sec + |
| 34 | PosixZeroTime.seconds_ ), |
| 35 | static_cast<TimeValue::NanoSecondsType>( the_time.tv_usec * |
| 36 | NANOSECONDS_PER_MICROSECOND ) ); |
| 37 | } |
Reid Spencer | 0d5716e | 2004-09-25 05:03:54 +0000 | [diff] [blame] | 38 | // vim: sw=2 smartindent smarttab tw=80 autoindent expandtab |
| 39 | |
| 40 | } |