blob: dbe7515cd248fbcac4e42a54845e0977afcff240 [file] [log] [blame]
Stéphane Marchesinae37e6c2014-08-08 18:19:40 -07001/*
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 Sodmanbbcb0522014-09-19 10:34:07 -070010#include <stdio.h>
11#include <stdlib.h>
12#include <stdarg.h>
David Sodmane46ea8a2015-03-13 15:47:12 -070013#include <stdbool.h>
David Sodmanbbcb0522014-09-19 10:34:07 -070014#include <time.h>
15
Stéphane Marchesinae37e6c2014-08-08 18:19:40 -070016#define MAX(A, B) ((A) > (B) ? (A) : (B))
17#define ARRAY_SIZE(A) (sizeof(A)/sizeof(*(A)))
18
David Sodmanbbcb0522014-09-19 10:34:07 -070019#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. */
24inline 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
30void LOG(int severity, const char* fmt, ...);
David Sodmane46ea8a2015-03-13 15:47:12 -070031void sync_lock(bool acquire);
David Sodmanbbcb0522014-09-19 10:34:07 -070032void daemonize();
33
34
35#define ERROR (1)
36#define WARNING (2)
37#define INFO (4)
38
Stéphane Marchesinae37e6c2014-08-08 18:19:40 -070039#endif