Tor 0.4.9.2-alpha-dev
All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Modules Pages
hashx_time.c
1/* Copyright (c) 2020 tevador <tevador@gmail.com> */
2/* See LICENSE for licensing information */
3
4#include "hashx_time.h"
5#include <hashx.h>
6
7#if defined(HASHX_WIN)
8#include <windows.h>
9#else
10#include <sys/time.h>
11#endif
12
13double hashx_time() {
14#ifdef HASHX_WIN
15 static double freq = 0;
16 if (freq == 0) {
17 LARGE_INTEGER freq_long;
18 if (!QueryPerformanceFrequency(&freq_long)) {
19 return 0;
20 }
21 freq = freq_long.QuadPart;
22 }
23 LARGE_INTEGER time;
24 if (!QueryPerformanceCounter(&time)) {
25 return 0;
26 }
27 return time.QuadPart / freq;
28#else
29 struct timeval time;
30 if (gettimeofday(&time, NULL) != 0) {
31 return 0;
32 }
33 return (double)time.tv_sec + (double)time.tv_usec * 1.0e-6;
34#endif
35}