6 /* Portability definitions. */
11 #define sleep(seconds) Sleep((seconds) * 1000)
12 #define __sync_fetch_and_add(ap, b) InterlockedExchangeAdd((unsigned long *) (ap), (b));
13 #define __sync_fetch_and_sub(ap, b) InterlockedExchangeAdd((unsigned long *) (ap), -(b));
16 static inline const char *
17 strcasestr(const char *haystack
, const char *needle
)
19 for (const char *p
= haystack
; *p
; p
++) {
20 for (int ni
= 0; needle
[ni
]; ni
++) {
23 if (toupper(p
[ni
]) != toupper(needle
[ni
]))
33 /* Misc. definitions. */
35 /* Use make DOUBLE=1 in large configurations with counts > 1M
36 * where 24 bits of floating_t mantissa become insufficient. */
38 # define floating_t double
39 # define PRIfloating "%lf"
41 # define floating_t float
42 # define PRIfloating "%f"
45 #define likely(x) __builtin_expect(!!(x), 1)
46 #define unlikely(x) __builtin_expect((x), 0)
49 checked_malloc(size_t size
, char *filename
, unsigned int line
, const char *func
)
51 void *p
= malloc(size
);
53 fprintf(stderr
, "%s:%u: %s: OUT OF MEMORY malloc(%zu)\n",
54 filename
, line
, func
, size
);
61 checked_calloc(size_t nmemb
, size_t size
, char *filename
, unsigned int line
, const char *func
)
63 void *p
= calloc(nmemb
, size
);
65 fprintf(stderr
, "%s:%u: %s: OUT OF MEMORY calloc(%zu, %zu)\n",
66 filename
, line
, func
, nmemb
, size
);
72 #define malloc2(size) checked_malloc((size), __FILE__, __LINE__, __func__)
73 #define calloc2(nmemb, size) checked_calloc((nmemb), (size), __FILE__, __LINE__, __func__)