TimeValue.cpp revision 249423
1218885Sdim//===-- TimeValue.cpp - Implement OS TimeValue Concept ----------*- C++ -*-===// 2218885Sdim// 3218885Sdim// The LLVM Compiler Infrastructure 4218885Sdim// 5218885Sdim// This file is distributed under the University of Illinois Open Source 6218885Sdim// License. See LICENSE.TXT for details. 7218885Sdim// 8218885Sdim//===----------------------------------------------------------------------===// 9218885Sdim// 10218885Sdim// This file implements the operating system TimeValue concept. 11218885Sdim// 12218885Sdim//===----------------------------------------------------------------------===// 13218885Sdim 14218885Sdim#include "llvm/Support/TimeValue.h" 15218885Sdim#include "llvm/Config/config.h" 16218885Sdim 17218885Sdimnamespace llvm { 18218885Sdimusing namespace sys; 19218885Sdim 20249423Sdimconst TimeValue::SecondsType 21249423Sdim TimeValue::PosixZeroTimeSeconds = -946684800; 22249423Sdimconst TimeValue::SecondsType 23249423Sdim TimeValue::Win32ZeroTimeSeconds = -12591158400ULL; 24249423Sdim 25218885Sdimconst TimeValue TimeValue::MinTime = TimeValue ( INT64_MIN,0 ); 26218885Sdimconst TimeValue TimeValue::MaxTime = TimeValue ( INT64_MAX,0 ); 27218885Sdimconst TimeValue TimeValue::ZeroTime = TimeValue ( 0,0 ); 28249423Sdimconst TimeValue TimeValue::PosixZeroTime = TimeValue ( PosixZeroTimeSeconds,0 ); 29249423Sdimconst TimeValue TimeValue::Win32ZeroTime = TimeValue ( Win32ZeroTimeSeconds,0 ); 30218885Sdim 31218885Sdimvoid 32218885SdimTimeValue::normalize( void ) { 33218885Sdim if ( nanos_ >= NANOSECONDS_PER_SECOND ) { 34218885Sdim do { 35218885Sdim seconds_++; 36218885Sdim nanos_ -= NANOSECONDS_PER_SECOND; 37218885Sdim } while ( nanos_ >= NANOSECONDS_PER_SECOND ); 38218885Sdim } else if (nanos_ <= -NANOSECONDS_PER_SECOND ) { 39218885Sdim do { 40218885Sdim seconds_--; 41218885Sdim nanos_ += NANOSECONDS_PER_SECOND; 42218885Sdim } while (nanos_ <= -NANOSECONDS_PER_SECOND); 43218885Sdim } 44218885Sdim 45218885Sdim if (seconds_ >= 1 && nanos_ < 0) { 46218885Sdim seconds_--; 47218885Sdim nanos_ += NANOSECONDS_PER_SECOND; 48218885Sdim } else if (seconds_ < 0 && nanos_ > 0) { 49218885Sdim seconds_++; 50218885Sdim nanos_ -= NANOSECONDS_PER_SECOND; 51218885Sdim } 52218885Sdim} 53218885Sdim 54218885Sdim} 55218885Sdim 56218885Sdim/// Include the platform specific portion of TimeValue class 57218885Sdim#ifdef LLVM_ON_UNIX 58218885Sdim#include "Unix/TimeValue.inc" 59218885Sdim#endif 60218885Sdim#ifdef LLVM_ON_WIN32 61218885Sdim#include "Windows/TimeValue.inc" 62218885Sdim#endif 63