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 /* Misc. definitions. */
18 /* Use make DOUBLE=1 in large configurations with counts > 1M
19 * where 24 bits of floating_t mantissa become insufficient. */
21 # define floating_t double
22 # define PRIfloating "%lf"
24 # define floating_t float
25 # define PRIfloating "%f"
28 #define likely(x) __builtin_expect(!!(x), 1)
29 #define unlikely(x) __builtin_expect((x), 0)
32 checked_malloc(size_t size
, char *filename
, unsigned int line
, const char *func
)
34 void *p
= malloc(size
);
36 fprintf(stderr
, "%s:%u: %s: OUT OF MEMORY malloc(%zu)\n",
37 filename
, line
, func
, size
);
44 checked_calloc(size_t nmemb
, size_t size
, char *filename
, unsigned int line
, const char *func
)
46 void *p
= calloc(nmemb
, size
);
48 fprintf(stderr
, "%s:%u: %s: OUT OF MEMORY calloc(%zu, %zu)\n",
49 filename
, line
, func
, nmemb
, size
);
55 #define malloc2(size) checked_malloc((size), __FILE__, __LINE__, __func__)
56 #define calloc2(nmemb, size) checked_calloc((nmemb), (size), __FILE__, __LINE__, __func__)