OLD | NEW |
(Empty) | |
| 1 // Copyright 2014 The Crashpad Authors. All rights reserved. |
| 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 #include "util/misc/clock.h" |
| 16 |
| 17 #include <time.h> |
| 18 |
| 19 #include "base/logging.h" |
| 20 #include "base/posix/eintr_wrapper.h" |
| 21 #include "build/build_config.h" |
| 22 |
| 23 namespace { |
| 24 |
| 25 const uint64_t kNanosecondsPerSecond = 1E9; |
| 26 |
| 27 } // namespace |
| 28 |
| 29 namespace crashpad { |
| 30 |
| 31 #if !defined(OS_MACOSX) |
| 32 |
| 33 uint64_t ClockMonotonicNanoseconds() { |
| 34 timespec now; |
| 35 int rv = clock_gettime(CLOCK_MONOTONIC, &now); |
| 36 DPCHECK(rv == 0) << "clock_gettime"; |
| 37 |
| 38 return now.tv_sec * kNanosecondsPerSecond + now.tv_nsec; |
| 39 } |
| 40 |
| 41 #endif |
| 42 |
| 43 void SleepNanoseconds(uint64_t nanoseconds) { |
| 44 timespec sleep_time; |
| 45 sleep_time.tv_sec = nanoseconds / kNanosecondsPerSecond; |
| 46 sleep_time.tv_nsec = nanoseconds % kNanosecondsPerSecond; |
| 47 int rv = HANDLE_EINTR(nanosleep(&sleep_time, &sleep_time)); |
| 48 DPCHECK(rv == 0) << "nanosleep"; |
| 49 } |
| 50 |
| 51 } // namespace crashpad |
OLD | NEW |