… | |
… | |
21 | |
21 | |
22 | #ifndef UTIL_H__ |
22 | #ifndef UTIL_H__ |
23 | #define UTIL_H__ |
23 | #define UTIL_H__ |
24 | |
24 | |
25 | //#define PREFER_MALLOC |
25 | //#define PREFER_MALLOC |
|
|
26 | //#define DEBUG_SALLOC |
26 | |
27 | |
27 | #if __GNUC__ >= 3 |
28 | #if __GNUC__ >= 3 |
28 | # define is_constant(c) __builtin_constant_p (c) |
29 | # define is_constant(c) __builtin_constant_p (c) |
29 | # define expect(expr,value) __builtin_expect ((expr),(value)) |
30 | # define expect(expr,value) __builtin_expect ((expr),(value)) |
30 | # define prefetch(addr,rw,locality) __builtin_prefetch (addr, rw, locality) |
31 | # define prefetch(addr,rw,locality) __builtin_prefetch (addr, rw, locality) |
… | |
… | |
51 | |
52 | |
52 | #include <glib.h> |
53 | #include <glib.h> |
53 | |
54 | |
54 | #include <shstr.h> |
55 | #include <shstr.h> |
55 | #include <traits.h> |
56 | #include <traits.h> |
|
|
57 | |
|
|
58 | #ifdef DEBUG_SALLOC |
|
|
59 | # define g_slice_alloc0(s) debug_slice_alloc0(s) |
|
|
60 | # define g_slice_alloc(s) debug_slice_alloc(s) |
|
|
61 | # define g_slice_free1(s,p) debug_slice_free1(s,p) |
|
|
62 | void *g_slice_alloc (unsigned long size); |
|
|
63 | void *g_slice_alloc0 (unsigned long size); |
|
|
64 | void g_slice_free1 (unsigned long size, void *ptr); |
|
|
65 | #endif |
56 | |
66 | |
57 | // use C0X decltype for auto declarations until ISO C++ sanctifies them (if ever) |
67 | // use C0X decltype for auto declarations until ISO C++ sanctifies them (if ever) |
58 | #define auto(var,expr) decltype(expr) var = (expr) |
68 | #define auto(var,expr) decltype(expr) var = (expr) |
59 | |
69 | |
60 | // very ugly macro that basicaly declares and initialises a variable |
70 | // very ugly macro that basicaly declares and initialises a variable |
… | |
… | |
547 | assign ((char *)&dst, src, N); |
557 | assign ((char *)&dst, src, N); |
548 | } |
558 | } |
549 | |
559 | |
550 | typedef double tstamp; |
560 | typedef double tstamp; |
551 | |
561 | |
552 | // return current time as timestampe |
562 | // return current time as timestamp |
553 | tstamp now (); |
563 | tstamp now (); |
554 | |
564 | |
555 | int similar_direction (int a, int b); |
565 | int similar_direction (int a, int b); |
556 | |
566 | |
557 | // like sprintf, but returns a "static" buffer |
567 | // like sprintf, but returns a "static" buffer |