]> pd.if.org Git - nbds/blob - include/common.h
Initial commit
[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 MAX_NUM_THREADS 4 // make this whatever you want, but make it a power of 2
15
16 #define CACHE_LINE_SIZE 64
17
18 #define CAT(x,y) x##y
19 #define ON_EXIT_SCOPE_I(x,i) \
20     inline void CAT(scope_cleanup_function_, i) (int *CAT(scope_cleanup_dummy_argument_, i)) { x; }; \
21     int CAT(scope_cleanup_dummy_variable_, i) __attribute__((cleanup(CAT(scope_cleanup_function_, i))));
22 #define ON_EXIT_SCOPE(x) ON_EXIT_SCOPE_I(x,__LINE__)
23
24 #define EXPECT_TRUE(x)     __builtin_expect(x, 1)
25 #define EXPECT_FALSE(x)    __builtin_expect(x, 0)
26
27 #define SYNC_SWAP          __sync_lock_test_and_set
28 #define SYNC_CAS           __sync_val_compare_and_swap
29 #define SYNC_ADD           __sync_add_and_fetch
30 #define SYNC_FETCH_AND_OR  __sync_fetch_and_or
31
32 #define MASK(n)     ((1LL << (n)) - 1)
33
34 #define TAG          (1LL << 63)
35 #define IS_TAGGED(v) ((int64_t)(v) < 0)
36 #define TAG_VALUE(v) ((int64_t)(v) |  TAG)
37 #define STRIP_TAG(v) ((int64_t)(v) & ~TAG)
38
39 #define TRUE  1
40 #define FALSE 0
41
42 typedef          long long  int64_t;
43 typedef unsigned long long uint64_t;
44 typedef unsigned int       uint32_t;
45
46 #include "lwt.h"
47 #endif //COMMON_H