]> pd.if.org Git - nbds/blob - include/common.h
introduce some more typedefs and conversion functions to improve portability
[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 calloc "DON'T USE CALLOC" // use nbd_malloc() instead
16 #define free   "DON'T USE FREE"   // use nbd_free() instead
17
18 #define MAX_NUM_THREADS 4 // make this whatever you want, but make it a power of 2
19
20 #define CACHE_LINE_SIZE 64
21
22 #define EXPECT_TRUE(x)     __builtin_expect(x, 1)
23 #define EXPECT_FALSE(x)    __builtin_expect(x, 0)
24
25 #define SYNC_SWAP          __sync_lock_test_and_set
26 #define SYNC_CAS           __sync_val_compare_and_swap
27 #define SYNC_ADD           __sync_add_and_fetch
28 #define SYNC_FETCH_AND_OR  __sync_fetch_and_or
29
30 #define MASK(n)     ((1ULL << (n)) - 1)
31
32 #define TRUE  1
33 #define FALSE 0
34
35 #define TAG1         (1ULL << 63)
36 #define TAG2         (1ULL << 62)
37 #define TAG_VALUE(v, tag) ((v) |  tag)
38 #define IS_TAGGED(v, tag) ((v) &  tag)
39 #define STRIP_TAG(v, tag) ((v) & ~tag)
40
41 #define DOES_NOT_EXIST 0
42 #define ERROR_INVALID_OPTION (-1)
43 #define ERROR_INVALID_ARGUMENT (-2)
44 #define ERROR_UNSUPPORTED_FEATURE (-3)
45 #define ERROR_TXN_NOT_RUNNING (-4)
46
47 typedef unsigned long long uint64_t;
48 typedef unsigned int       uint32_t;
49 typedef unsigned char      uint8_t;
50
51 typedef uint64_t markable_t;
52
53 #include "lwt.h"
54 #endif //COMMON_H