Paul Stewart | e692740 | 2012-01-23 16:11:30 -0800 | [diff] [blame] | 1 | // Copyright (c) 2012 The Chromium OS Authors. All rights reserved. |
Paul Stewart | c2350ee | 2011-10-19 12:28:40 -0700 | [diff] [blame] | 2 | // 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 Stewart | e692740 | 2012-01-23 16:11:30 -0800 | [diff] [blame] | 7 | #include <time.h> |
| 8 | |
Paul Stewart | c2350ee | 2011-10-19 12:28:40 -0700 | [diff] [blame] | 9 | namespace shill { |
| 10 | |
Eric Shienbrood | 3e20a23 | 2012-02-16 11:35:56 -0500 | [diff] [blame] | 11 | // TODO(ers): not using LAZY_INSTANCE_INITIALIZER |
| 12 | // because of http://crbug.com/114828 |
| 13 | static base::LazyInstance<Time> g_time = {0, {{0}}}; |
Paul Stewart | c2350ee | 2011-10-19 12:28:40 -0700 | [diff] [blame] | 14 | |
| 15 | Time::Time() { } |
| 16 | |
| 17 | Time::~Time() { } |
| 18 | |
| 19 | Time* Time::GetInstance() { |
| 20 | return g_time.Pointer(); |
| 21 | } |
| 22 | |
Paul Stewart | e692740 | 2012-01-23 16:11:30 -0800 | [diff] [blame] | 23 | int 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 Stewart | c2350ee | 2011-10-19 12:28:40 -0700 | [diff] [blame] | 34 | int Time::GetTimeOfDay(struct timeval *tv, struct timezone *tz) { |
| 35 | return gettimeofday(tv, tz); |
| 36 | } |
| 37 | |
| 38 | } // namespace shill |