]> arthur.barton.de Git - netdata.git/blob - src/common.h
71ef6f691dc43361e0eb92739b706ed8399dd63a
[netdata.git] / src / common.h
1 #include <inttypes.h>
2 #include <sys/types.h>
3 #include <unistd.h>
4
5 #ifndef NETDATA_COMMON_H
6 #define NETDATA_COMMON_H 1
7
8 #define abs(x) ((x < 0)? -x : x)
9 #define usecdiff(now, last) (((((now)->tv_sec * 1000000ULL) + (now)->tv_usec) - (((last)->tv_sec * 1000000ULL) + (last)->tv_usec)))
10
11 extern uint32_t simple_hash(const char *name);
12 extern void strreverse(char* begin, char* end);
13 extern char *mystrsep(char **ptr, char *s);
14 extern char *trim(char *s);
15
16 extern void *mymmap(const char *filename, unsigned long size, int flags);
17 extern int savememory(const char *filename, void *mem, unsigned long size);
18
19 extern int fd_is_valid(int fd);
20
21 extern char *global_host_prefix;
22
23 #ifdef __GNUC__
24 // gcc branch optimization
25 // #warning "Using GCC branch optimizations"
26 #define likely(x)       __builtin_expect(!!(x), 1)
27 #define unlikely(x)     __builtin_expect(!!(x), 0)
28 #else
29 #define likely(x)       (x)
30 #define unlikely(x)     (x)
31 #endif
32
33
34 /* Number of ticks per second */
35 #define HZ              hz
36 extern unsigned int hz;
37 extern void get_HZ(void);
38
39 extern pid_t gettid(void);
40
41 #endif /* NETDATA_COMMON_H */