Stéphane Marchesin | ae37e6c | 2014-08-08 18:19:40 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2014 The Chromium OS Authors. All rights reserved. |
| 3 | * Use of this source code is governed by a BSD-style license that can be |
| 4 | * found in the LICENSE file. |
| 5 | */ |
| 6 | |
| 7 | #ifndef UTIL_H |
| 8 | #define UTIL_H |
| 9 | |
David Sodman | bbcb052 | 2014-09-19 10:34:07 -0700 | [diff] [blame] | 10 | #include <stdio.h> |
| 11 | #include <stdlib.h> |
| 12 | #include <stdarg.h> |
David Sodman | e46ea8a | 2015-03-13 15:47:12 -0700 | [diff] [blame^] | 13 | #include <stdbool.h> |
David Sodman | bbcb052 | 2014-09-19 10:34:07 -0700 | [diff] [blame] | 14 | #include <time.h> |
| 15 | |
Stéphane Marchesin | ae37e6c | 2014-08-08 18:19:40 -0700 | [diff] [blame] | 16 | #define MAX(A, B) ((A) > (B) ? (A) : (B)) |
| 17 | #define ARRAY_SIZE(A) (sizeof(A)/sizeof(*(A))) |
| 18 | |
David Sodman | bbcb052 | 2014-09-19 10:34:07 -0700 | [diff] [blame] | 19 | #define MS_PER_SEC (1000LL) |
| 20 | #define NS_PER_SEC (1000LL * 1000LL * 1000LL) |
| 21 | #define NS_PER_MS (NS_PER_SEC / MS_PER_SEC); |
| 22 | |
| 23 | /* Returns the current CLOCK_MONOTONIC time in milliseconds. */ |
| 24 | inline int64_t get_monotonic_time_ms() { |
| 25 | struct timespec spec; |
| 26 | clock_gettime(CLOCK_MONOTONIC, &spec); |
| 27 | return MS_PER_SEC * spec.tv_sec + spec.tv_nsec / NS_PER_MS; |
| 28 | } |
| 29 | |
| 30 | void LOG(int severity, const char* fmt, ...); |
David Sodman | e46ea8a | 2015-03-13 15:47:12 -0700 | [diff] [blame^] | 31 | void sync_lock(bool acquire); |
David Sodman | bbcb052 | 2014-09-19 10:34:07 -0700 | [diff] [blame] | 32 | void daemonize(); |
| 33 | |
| 34 | |
| 35 | #define ERROR (1) |
| 36 | #define WARNING (2) |
| 37 | #define INFO (4) |
| 38 | |
Stéphane Marchesin | ae37e6c | 2014-08-08 18:19:40 -0700 | [diff] [blame] | 39 | #endif |