]> pd.if.org Git - nbds/blob - include/common.h
code cleanup
[nbds] / include / common.h
1 /* 
2  * Written by Josh Dybnis and released to the public domain, as explained at
3  * http://creativecommons.org/licenses/publicdomain
4  */
5 #ifndef COMMON_H
6 #define COMMON_H
7
8 #include <stdlib.h>
9 #include <assert.h>
10 #include <limits.h>
11 #include <string.h>
12 #include <sys/types.h>
13
14 #define malloc "DON'T USE MALLOC" // use nbd_malloc() instead
15 #define free   "DON'T USE FREE"   // use nbd_free() instead
16
17 #define MAX_NUM_THREADS 4 // make this whatever you want, but make it a power of 2
18
19 #define CACHE_LINE_SIZE 64
20
21 #define EXPECT_TRUE(x)     __builtin_expect(x, 1)
22 #define EXPECT_FALSE(x)    __builtin_expect(x, 0)
23
24 #define SYNC_SWAP          __sync_lock_test_and_set
25 #define SYNC_CAS           __sync_val_compare_and_swap
26 #define SYNC_ADD           __sync_add_and_fetch
27 #define SYNC_FETCH_AND_OR  __sync_fetch_and_or
28
29 #define MASK(n)     ((1ULL << (n)) - 1)
30
31 #define TRUE  1
32 #define FALSE 0
33
34 #define TAG          (1ULL << 63)
35 #define TAG_VALUE(v) ((uint64_t)(v) |  TAG)
36 #define IS_TAGGED(v) ((uint64_t)(v) &  TAG)
37 #define STRIP_TAG(v) ((uint64_t)(v) & ~TAG)
38
39 typedef unsigned long long uint64_t;
40 typedef unsigned int       uint32_t;
41 typedef unsigned char      uint8_t;
42
43 #include "lwt.h"
44 #endif //COMMON_H