VirtualBox

source: vbox/trunk/src/VBox/Runtime/r3/posix/time-posix.cpp@ 5285

Last change on this file since 5285 was 4071, checked in by vboxsync, 17 years ago

Biggest check-in ever. New source code headers for all (C) innotek files.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
File size: 2.2 KB
Line 
1/* $Id: time-posix.cpp 4071 2007-08-07 17:07:59Z vboxsync $ */
2/** @file
3 * innotek Portable Runtime - Time, POSIX.
4 */
5
6/*
7 * Copyright (C) 2006-2007 innotek GmbH
8 *
9 * This file is part of VirtualBox Open Source Edition (OSE), as
10 * available from http://www.virtualbox.org. This file is free software;
11 * you can redistribute it and/or modify it under the terms of the GNU
12 * General Public License as published by the Free Software Foundation,
13 * in version 2 as it comes in the "COPYING" file of the VirtualBox OSE
14 * distribution. VirtualBox OSE is distributed in the hope that it will
15 * be useful, but WITHOUT ANY WARRANTY of any kind.
16 */
17
18
19/*******************************************************************************
20* Header Files *
21*******************************************************************************/
22#define LOG_GROUP RTLOGGROUP_TIME
23#define RTTIME_INCL_TIMEVAL
24#include <sys/time.h>
25#include <time.h>
26
27#include <iprt/time.h>
28#include "internal/time.h"
29
30
31DECLINLINE(uint64_t) rtTimeGetSystemNanoTS(void)
32{
33#if defined(CLOCK_MONOTONIC) && !defined(RT_OS_L4) && !defined(RT_OS_OS2)
34 /* check monotonic clock first. */
35 static bool s_fMonoClock = true;
36 if (s_fMonoClock)
37 {
38 struct timespec ts;
39 if (!clock_gettime(CLOCK_MONOTONIC, &ts))
40 return (uint64_t)ts.tv_sec * (uint64_t)(1000 * 1000 * 1000)
41 + ts.tv_nsec;
42 s_fMonoClock = false;
43 }
44#endif
45
46 /* fallback to gettimeofday(). */
47 struct timeval tv;
48 gettimeofday(&tv, NULL);
49 return (uint64_t)tv.tv_sec * (uint64_t)(1000 * 1000 * 1000)
50 + (uint64_t)(tv.tv_usec * 1000);
51}
52
53
54/**
55 * Gets the current nanosecond timestamp.
56 *
57 * This differs from RTTimeNanoTS in that it will use system APIs and not do any
58 * resolution or performance optimizations.
59 *
60 * @returns nanosecond timestamp.
61 */
62RTDECL(uint64_t) RTTimeSystemNanoTS(void)
63{
64 return rtTimeGetSystemNanoTS();
65}
66
67
68/**
69 * Gets the current millisecond timestamp.
70 *
71 * This differs from RTTimeNanoTS in that it will use system APIs and not do any
72 * resolution or performance optimizations.
73 *
74 * @returns millisecond timestamp.
75 */
76RTDECL(uint64_t) RTTimeSystemMilliTS(void)
77{
78 return rtTimeGetSystemNanoTS() / 1000000;
79}
80
Note: See TracBrowser for help on using the repository browser.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette