2 * Written by Josh Dybnis and released to the public domain, as explained at
3 * http://creativecommons.org/licenses/publicdomain
12 #include <sys/types.h>
14 #define malloc "DON'T USE MALLOC" // use nbd_malloc() instead
15 #define free "DON'T USE FREE" // use nbd_free() instead
17 #define MAX_NUM_THREADS 4 // make this whatever you want, but make it a power of 2
19 #define CACHE_LINE_SIZE 64
22 #define ON_EXIT_SCOPE_I(x,i) \
23 inline void CAT(scope_cleanup_function_, i) (int *CAT(scope_cleanup_dummy_argument_, i)) { x; }; \
24 int CAT(scope_cleanup_dummy_variable_, i) __attribute__((cleanup(CAT(scope_cleanup_function_, i))));
25 #define ON_EXIT_SCOPE(x) ON_EXIT_SCOPE_I(x,__LINE__)
27 #define EXPECT_TRUE(x) __builtin_expect(x, 1)
28 #define EXPECT_FALSE(x) __builtin_expect(x, 0)
30 #define SYNC_SWAP __sync_lock_test_and_set
31 #define SYNC_CAS __sync_val_compare_and_swap
32 #define SYNC_ADD __sync_add_and_fetch
33 #define SYNC_FETCH_AND_OR __sync_fetch_and_or
35 #define MASK(n) ((1LL << (n)) - 1)
37 #define TAG (1LL << 63)
38 #define IS_TAGGED(v) ((int64_t)(v) < 0)
39 #define TAG_VALUE(v) ((uint64_t)(v) | TAG)
40 #define STRIP_TAG(v) ((uint64_t)(v) & ~TAG)
45 typedef unsigned long long uint64_t;
46 typedef unsigned int uint32_t;
47 typedef unsigned char uint8_t;