LLVM API Documentation

TimeValue.cpp

Go to the documentation of this file.
00001 //===-- TimeValue.cpp - Implement OS TimeValue Concept ----------*- C++ -*-===//
00002 //
00003 //                     The LLVM Compiler Infrastructure
00004 //
00005 // This file was developed by Reid Spencer and is distributed under the
00006 // University of Illinois Open Source License. See LICENSE.TXT for details.
00007 //
00008 //===----------------------------------------------------------------------===//
00009 //
00010 //  This file implements the operating system TimeValue concept.
00011 //
00012 //===----------------------------------------------------------------------===//
00013 
00014 #include "llvm/System/TimeValue.h"
00015 #include "llvm/Config/config.h"
00016 
00017 namespace llvm {
00018 using namespace sys;
00019 
00020 const TimeValue TimeValue::MinTime       = TimeValue ( INT64_MIN,0 );
00021 const TimeValue TimeValue::MaxTime       = TimeValue ( INT64_MAX,0 );
00022 const TimeValue TimeValue::ZeroTime      = TimeValue ( 0,0 );
00023 const TimeValue TimeValue::PosixZeroTime = TimeValue ( -946684800,0 );
00024 const TimeValue TimeValue::Win32ZeroTime = TimeValue ( -12591158400ULL,0 );
00025 
00026 void
00027 TimeValue::normalize( void ) {
00028   if ( nanos_ >= NANOSECONDS_PER_SECOND ) {
00029     do {
00030       seconds_++;
00031       nanos_ -= NANOSECONDS_PER_SECOND;
00032     } while ( nanos_ >= NANOSECONDS_PER_SECOND );
00033   } else if (nanos_ <= -NANOSECONDS_PER_SECOND ) {
00034     do {
00035       seconds_--;
00036       nanos_ += NANOSECONDS_PER_SECOND;
00037     } while (nanos_ <= -NANOSECONDS_PER_SECOND);
00038   }
00039 
00040   if (seconds_ >= 1 && nanos_ < 0) {
00041     seconds_--;
00042     nanos_ += NANOSECONDS_PER_SECOND;
00043   } else if (seconds_ < 0 && nanos_ > 0) {
00044     seconds_++;
00045     nanos_ -= NANOSECONDS_PER_SECOND;
00046   }
00047 }
00048 
00049 }
00050 
00051 /// Include the platform specific portion of TimeValue class
00052 #ifdef LLVM_ON_UNIX
00053 #include "Unix/TimeValue.inc"
00054 #endif
00055 #ifdef LLVM_ON_WIN32
00056 #include "Win32/TimeValue.inc"
00057 #endif
00058 
00059 DEFINING_FILE_FOR(SystemTimeValue)