TimeValue.cpp revision 296417
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 { 18296417Sdim 19218885Sdimusing namespace sys; 20218885Sdim 21249423Sdimconst TimeValue::SecondsType 22249423Sdim TimeValue::PosixZeroTimeSeconds = -946684800; 23249423Sdimconst TimeValue::SecondsType 24249423Sdim TimeValue::Win32ZeroTimeSeconds = -12591158400ULL; 25249423Sdim 26296417Sdimvoid TimeValue::normalize() { 27218885Sdim if ( nanos_ >= NANOSECONDS_PER_SECOND ) { 28218885Sdim do { 29218885Sdim seconds_++; 30218885Sdim nanos_ -= NANOSECONDS_PER_SECOND; 31218885Sdim } while ( nanos_ >= NANOSECONDS_PER_SECOND ); 32218885Sdim } else if (nanos_ <= -NANOSECONDS_PER_SECOND ) { 33218885Sdim do { 34218885Sdim seconds_--; 35218885Sdim nanos_ += NANOSECONDS_PER_SECOND; 36218885Sdim } while (nanos_ <= -NANOSECONDS_PER_SECOND); 37218885Sdim } 38218885Sdim 39218885Sdim if (seconds_ >= 1 && nanos_ < 0) { 40218885Sdim seconds_--; 41218885Sdim nanos_ += NANOSECONDS_PER_SECOND; 42218885Sdim } else if (seconds_ < 0 && nanos_ > 0) { 43218885Sdim seconds_++; 44218885Sdim nanos_ -= NANOSECONDS_PER_SECOND; 45218885Sdim } 46218885Sdim} 47218885Sdim 48296417Sdim} // namespace llvm 49218885Sdim 50276479Sdim/// Include the platform-specific portion of TimeValue class 51218885Sdim#ifdef LLVM_ON_UNIX 52218885Sdim#include "Unix/TimeValue.inc" 53218885Sdim#endif 54218885Sdim#ifdef LLVM_ON_WIN32 55218885Sdim#include "Windows/TimeValue.inc" 56218885Sdim#endif 57