MongoDB C++ Driver legacy-1.1.2
Loading...
Searching...
No Matches
timer-posixclock-inl.h
1/* Copyright 2010 10gen Inc.
2 *
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 */
15
24#define MONGO_TIMER_IMPL_POSIX_MONOTONIC_CLOCK
25
26#include <ctime>
27
28#include "mongo/util/assert_util.h"
29
30namespace mongo {
31
32unsigned long long Timer::now() const {
33 timespec the_time;
34 unsigned long long result;
35
36 fassert(16160, !clock_gettime(CLOCK_MONOTONIC, &the_time));
37
38 // Safe for 292 years after the clock epoch, even if we switch to a signed time value. On
39 // Linux, the monotonic clock's epoch is the UNIX epoch.
40 result = static_cast<unsigned long long>(the_time.tv_sec);
41 result *= nanosPerSecond;
42 result += static_cast<unsigned long long>(the_time.tv_nsec);
43 return result;
44}
45
46} // namespace mongo
Utility functions for parsing numbers from strings.
Definition compare_numbers.h:20
MONGO_CLIENT_API void MONGO_CLIENT_FUNC fassert(int msgid, bool testOK)
aborts on condition failure
Definition assert_util.h:210