Reid Spencer | 9926c31 | 2004-09-24 23:25:19 +0000 | [diff] [blame] | 1 | //===-- TimeValue.cpp - Implement OS TimeValue Concept ----------*- C++ -*-===// |
Misha Brukman | f976c85 | 2005-04-21 22:55:34 +0000 | [diff] [blame] | 2 | // |
Reid Spencer | 9926c31 | 2004-09-24 23:25:19 +0000 | [diff] [blame] | 3 | // The LLVM Compiler Infrastructure |
| 4 | // |
Chris Lattner | 4ee451d | 2007-12-29 20:36:04 +0000 | [diff] [blame] | 5 | // This file is distributed under the University of Illinois Open Source |
| 6 | // License. See LICENSE.TXT for details. |
Misha Brukman | f976c85 | 2005-04-21 22:55:34 +0000 | [diff] [blame] | 7 | // |
Reid Spencer | 9926c31 | 2004-09-24 23:25:19 +0000 | [diff] [blame] | 8 | //===----------------------------------------------------------------------===// |
| 9 | // |
| 10 | // This file implements the operating system TimeValue concept. |
| 11 | // |
| 12 | //===----------------------------------------------------------------------===// |
| 13 | |
Michael J. Spencer | 1f6efa3 | 2010-11-29 18:16:10 +0000 | [diff] [blame] | 14 | #include "llvm/Support/TimeValue.h" |
Reid Spencer | c33e493 | 2004-12-27 06:16:38 +0000 | [diff] [blame] | 15 | #include "llvm/Config/config.h" |
Reid Spencer | 9926c31 | 2004-09-24 23:25:19 +0000 | [diff] [blame] | 16 | |
| 17 | namespace llvm { |
| 18 | using namespace sys; |
| 19 | |
Alexey Samsonov | 9f306bd | 2013-02-19 11:35:39 +0000 | [diff] [blame] | 20 | const TimeValue::SecondsType |
| 21 | TimeValue::PosixZeroTimeSeconds = -946684800; |
| 22 | const TimeValue::SecondsType |
| 23 | TimeValue::Win32ZeroTimeSeconds = -12591158400ULL; |
| 24 | |
Reid Spencer | 44cbf36 | 2004-11-14 22:06:18 +0000 | [diff] [blame] | 25 | const TimeValue TimeValue::MinTime = TimeValue ( INT64_MIN,0 ); |
| 26 | const TimeValue TimeValue::MaxTime = TimeValue ( INT64_MAX,0 ); |
| 27 | const TimeValue TimeValue::ZeroTime = TimeValue ( 0,0 ); |
Alexey Samsonov | 9f306bd | 2013-02-19 11:35:39 +0000 | [diff] [blame] | 28 | const TimeValue TimeValue::PosixZeroTime = TimeValue ( PosixZeroTimeSeconds,0 ); |
| 29 | const TimeValue TimeValue::Win32ZeroTime = TimeValue ( Win32ZeroTimeSeconds,0 ); |
Reid Spencer | 9926c31 | 2004-09-24 23:25:19 +0000 | [diff] [blame] | 30 | |
| 31 | void |
| 32 | TimeValue::normalize( void ) { |
| 33 | if ( nanos_ >= NANOSECONDS_PER_SECOND ) { |
| 34 | do { |
| 35 | seconds_++; |
| 36 | nanos_ -= NANOSECONDS_PER_SECOND; |
| 37 | } while ( nanos_ >= NANOSECONDS_PER_SECOND ); |
| 38 | } else if (nanos_ <= -NANOSECONDS_PER_SECOND ) { |
| 39 | do { |
| 40 | seconds_--; |
| 41 | nanos_ += NANOSECONDS_PER_SECOND; |
| 42 | } while (nanos_ <= -NANOSECONDS_PER_SECOND); |
| 43 | } |
| 44 | |
| 45 | if (seconds_ >= 1 && nanos_ < 0) { |
| 46 | seconds_--; |
| 47 | nanos_ += NANOSECONDS_PER_SECOND; |
| 48 | } else if (seconds_ < 0 && nanos_ > 0) { |
| 49 | seconds_++; |
| 50 | nanos_ -= NANOSECONDS_PER_SECOND; |
| 51 | } |
| 52 | } |
| 53 | |
| 54 | } |
| 55 | |
| 56 | /// Include the platform specific portion of TimeValue class |
Reid Spencer | c33e493 | 2004-12-27 06:16:38 +0000 | [diff] [blame] | 57 | #ifdef LLVM_ON_UNIX |
Reid Spencer | bccc8ab | 2005-01-09 23:29:00 +0000 | [diff] [blame] | 58 | #include "Unix/TimeValue.inc" |
Reid Spencer | c33e493 | 2004-12-27 06:16:38 +0000 | [diff] [blame] | 59 | #endif |
| 60 | #ifdef LLVM_ON_WIN32 |
Michael J. Spencer | 1f6efa3 | 2010-11-29 18:16:10 +0000 | [diff] [blame] | 61 | #include "Windows/TimeValue.inc" |
Reid Spencer | c33e493 | 2004-12-27 06:16:38 +0000 | [diff] [blame] | 62 | #endif |