| 1 | /* |
| 2 | * Copyright 2008-2018 Aerospike, Inc. |
| 3 | * |
| 4 | * Portions may be licensed to Aerospike, Inc. under one or more contributor |
| 5 | * license agreements. |
| 6 | * |
| 7 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not |
| 8 | * use this file except in compliance with the License. You may obtain a copy of |
| 9 | * the License at http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | * |
| 11 | * Unless required by applicable law or agreed to in writing, software |
| 12 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT |
| 13 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the |
| 14 | * License for the specific language governing permissions and limitations under |
| 15 | * the License. |
| 16 | */ |
| 17 | #include <citrusleaf/cf_clock.h> |
| 18 | |
| 19 | #if !defined(_MSC_VER) |
| 20 | |
| 21 | bool |
| 22 | cf_clock_init() |
| 23 | { |
| 24 | return true; |
| 25 | } |
| 26 | |
| 27 | #else |
| 28 | |
| 29 | double cf_clock_freq = 0.0; |
| 30 | int64_t cf_clock_start = 0; |
| 31 | uint64_t cf_wall_clock_start = 0; |
| 32 | |
| 33 | static bool |
| 34 | clock_init() |
| 35 | { |
| 36 | LARGE_INTEGER li; |
| 37 | |
| 38 | if (!QueryPerformanceFrequency(&li)) { |
| 39 | return false; |
| 40 | } |
| 41 | |
| 42 | cf_clock_freq = (double)li.QuadPart / (1000.0 * 1000.0 * 1000.0); |
| 43 | QueryPerformanceCounter(&li); |
| 44 | cf_clock_start = li.QuadPart; |
| 45 | return true; |
| 46 | } |
| 47 | |
| 48 | static void |
| 49 | wall_clock_init() |
| 50 | { |
| 51 | SYSTEMTIME s; |
| 52 | FILETIME f; |
| 53 | |
| 54 | s.wYear = 1970; |
| 55 | s.wMonth = 1; |
| 56 | s.wDay = 1; |
| 57 | s.wHour = 0; |
| 58 | s.wMinute = 0; |
| 59 | s.wSecond = 0; |
| 60 | s.wMilliseconds = 0; |
| 61 | SystemTimeToFileTime(&s, &f); |
| 62 | |
| 63 | cf_wall_clock_start = ((uint64_t)f.dwHighDateTime << 32) + (uint64_t)f.dwLowDateTime; |
| 64 | } |
| 65 | |
| 66 | bool |
| 67 | cf_clock_init() |
| 68 | { |
| 69 | wall_clock_init(); |
| 70 | return clock_init(); |
| 71 | } |
| 72 | #endif |
| 73 | |