blob: bd8af174bcd048fbef9f59469844be915ad65bc3 [file] [log] [blame]
Reid Spencer9926c312004-09-24 23:25:19 +00001//===-- TimeValue.cpp - Implement OS TimeValue Concept ----------*- C++ -*-===//
Misha Brukmanf976c852005-04-21 22:55:34 +00002//
Reid Spencer9926c312004-09-24 23:25:19 +00003// The LLVM Compiler Infrastructure
4//
Chris Lattner4ee451d2007-12-29 20:36:04 +00005// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
Misha Brukmanf976c852005-04-21 22:55:34 +00007//
Reid Spencer9926c312004-09-24 23:25:19 +00008//===----------------------------------------------------------------------===//
9//
10// This file implements the operating system TimeValue concept.
11//
12//===----------------------------------------------------------------------===//
13
Michael J. Spencer1f6efa32010-11-29 18:16:10 +000014#include "llvm/Support/TimeValue.h"
Reid Spencerc33e4932004-12-27 06:16:38 +000015#include "llvm/Config/config.h"
Reid Spencer9926c312004-09-24 23:25:19 +000016
17namespace llvm {
18using namespace sys;
19
Alexey Samsonov9f306bd2013-02-19 11:35:39 +000020const TimeValue::SecondsType
21 TimeValue::PosixZeroTimeSeconds = -946684800;
22const TimeValue::SecondsType
23 TimeValue::Win32ZeroTimeSeconds = -12591158400ULL;
24
Reid Spencer44cbf362004-11-14 22:06:18 +000025const TimeValue TimeValue::MinTime = TimeValue ( INT64_MIN,0 );
26const TimeValue TimeValue::MaxTime = TimeValue ( INT64_MAX,0 );
27const TimeValue TimeValue::ZeroTime = TimeValue ( 0,0 );
Alexey Samsonov9f306bd2013-02-19 11:35:39 +000028const TimeValue TimeValue::PosixZeroTime = TimeValue ( PosixZeroTimeSeconds,0 );
29const TimeValue TimeValue::Win32ZeroTime = TimeValue ( Win32ZeroTimeSeconds,0 );
Reid Spencer9926c312004-09-24 23:25:19 +000030
31void
32TimeValue::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 Spencerc33e4932004-12-27 06:16:38 +000057#ifdef LLVM_ON_UNIX
Reid Spencerbccc8ab2005-01-09 23:29:00 +000058#include "Unix/TimeValue.inc"
Reid Spencerc33e4932004-12-27 06:16:38 +000059#endif
60#ifdef LLVM_ON_WIN32
Michael J. Spencer1f6efa32010-11-29 18:16:10 +000061#include "Windows/TimeValue.inc"
Reid Spencerc33e4932004-12-27 06:16:38 +000062#endif