Reid Spencer | ca141a5 | 2004-09-24 23:25:19 +0000 | [diff] [blame] | 1 | //===-- TimeValue.cpp - Implement OS TimeValue Concept ----------*- C++ -*-===// |
Misha Brukman | 10468d8 | 2005-04-21 22:55:34 +0000 | [diff] [blame] | 2 | // |
Reid Spencer | ca141a5 | 2004-09-24 23:25:19 +0000 | [diff] [blame] | 3 | // The LLVM Compiler Infrastructure |
| 4 | // |
Chris Lattner | f3ebc3f | 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 | 10468d8 | 2005-04-21 22:55:34 +0000 | [diff] [blame] | 7 | // |
Reid Spencer | ca141a5 | 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 | 447762d | 2010-11-29 18:16:10 +0000 | [diff] [blame] | 14 | #include "llvm/Support/TimeValue.h" |
Reid Spencer | af6d3d5 | 2004-12-27 06:16:38 +0000 | [diff] [blame] | 15 | #include "llvm/Config/config.h" |
Reid Spencer | ca141a5 | 2004-09-24 23:25:19 +0000 | [diff] [blame] | 16 | |
| 17 | namespace llvm { |
Eugene Zelenko | ffec81c | 2015-11-04 22:32:32 +0000 | [diff] [blame] | 18 | |
Reid Spencer | ca141a5 | 2004-09-24 23:25:19 +0000 | [diff] [blame] | 19 | using namespace sys; |
| 20 | |
Alexey Samsonov | f940f0c | 2013-02-19 11:35:39 +0000 | [diff] [blame] | 21 | const TimeValue::SecondsType |
| 22 | TimeValue::PosixZeroTimeSeconds = -946684800; |
| 23 | const TimeValue::SecondsType |
| 24 | TimeValue::Win32ZeroTimeSeconds = -12591158400ULL; |
| 25 | |
Eugene Zelenko | ffec81c | 2015-11-04 22:32:32 +0000 | [diff] [blame] | 26 | void TimeValue::normalize() { |
Reid Spencer | ca141a5 | 2004-09-24 23:25:19 +0000 | [diff] [blame] | 27 | if ( nanos_ >= NANOSECONDS_PER_SECOND ) { |
| 28 | do { |
| 29 | seconds_++; |
| 30 | nanos_ -= NANOSECONDS_PER_SECOND; |
| 31 | } while ( nanos_ >= NANOSECONDS_PER_SECOND ); |
| 32 | } else if (nanos_ <= -NANOSECONDS_PER_SECOND ) { |
| 33 | do { |
| 34 | seconds_--; |
| 35 | nanos_ += NANOSECONDS_PER_SECOND; |
| 36 | } while (nanos_ <= -NANOSECONDS_PER_SECOND); |
| 37 | } |
| 38 | |
| 39 | if (seconds_ >= 1 && nanos_ < 0) { |
| 40 | seconds_--; |
| 41 | nanos_ += NANOSECONDS_PER_SECOND; |
| 42 | } else if (seconds_ < 0 && nanos_ > 0) { |
| 43 | seconds_++; |
| 44 | nanos_ -= NANOSECONDS_PER_SECOND; |
| 45 | } |
| 46 | } |
| 47 | |
Eugene Zelenko | ffec81c | 2015-11-04 22:32:32 +0000 | [diff] [blame] | 48 | } // namespace llvm |
Reid Spencer | ca141a5 | 2004-09-24 23:25:19 +0000 | [diff] [blame] | 49 | |
Alp Toker | cf21875 | 2014-06-30 18:57:16 +0000 | [diff] [blame] | 50 | /// Include the platform-specific portion of TimeValue class |
Reid Spencer | af6d3d5 | 2004-12-27 06:16:38 +0000 | [diff] [blame] | 51 | #ifdef LLVM_ON_UNIX |
Reid Spencer | c892a0d | 2005-01-09 23:29:00 +0000 | [diff] [blame] | 52 | #include "Unix/TimeValue.inc" |
Reid Spencer | af6d3d5 | 2004-12-27 06:16:38 +0000 | [diff] [blame] | 53 | #endif |
| 54 | #ifdef LLVM_ON_WIN32 |
Michael J. Spencer | 447762d | 2010-11-29 18:16:10 +0000 | [diff] [blame] | 55 | #include "Windows/TimeValue.inc" |
Reid Spencer | af6d3d5 | 2004-12-27 06:16:38 +0000 | [diff] [blame] | 56 | #endif |