blob: c55c15204f95e75db032de3277d93f085511c8ff [file] [log] [blame]
Paul Stewarte6927402012-01-23 16:11:30 -08001// Copyright (c) 2012 The Chromium OS Authors. All rights reserved.
Paul Stewartc2350ee2011-10-19 12:28:40 -07002// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5#include "shill/shill_time.h"
6
Paul Stewarte6927402012-01-23 16:11:30 -08007#include <time.h>
8
Paul Stewartc2350ee2011-10-19 12:28:40 -07009namespace shill {
10
Eric Shienbrood3e20a232012-02-16 11:35:56 -050011// TODO(ers): not using LAZY_INSTANCE_INITIALIZER
12// because of http://crbug.com/114828
13static base::LazyInstance<Time> g_time = {0, {{0}}};
Paul Stewartc2350ee2011-10-19 12:28:40 -070014
15Time::Time() { }
16
17Time::~Time() { }
18
19Time* Time::GetInstance() {
20 return g_time.Pointer();
21}
22
Paul Stewarte6927402012-01-23 16:11:30 -080023int Time::GetTimeMonotonic(struct timeval *tv) {
24 struct timespec ts;
25 if (clock_gettime(CLOCK_MONOTONIC, &ts) != 0) {
26 return -1;
27 }
28
29 tv->tv_sec = ts.tv_sec;
30 tv->tv_usec = ts.tv_nsec / 1000;
31 return 0;
32}
33
Paul Stewartc2350ee2011-10-19 12:28:40 -070034int Time::GetTimeOfDay(struct timeval *tv, struct timezone *tz) {
35 return gettimeofday(tv, tz);
36}
37
38} // namespace shill