summaryrefslogtreecommitdiff
path: root/src/include/lint.h
blob: 6ee6e7b7752583f5a282484ef5156541a21eda44 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
/*-
 * Copyright (c) 2014-2015 MongoDB, Inc.
 * Copyright (c) 2008-2014 WiredTiger, Inc.
 *	All rights reserved.
 *
 * See the file LICENSE for redistribution information.
 */

#define	WT_SIZET_FMT	"zu"			/* size_t format string */

#define	WT_COMPILER_TYPE_ALIGN(x)

#define	WT_PACKED_STRUCT_BEGIN(name)					\
	struct name {
#define	WT_PACKED_STRUCT_END						\
	};

#define	WT_GCC_FUNC_ATTRIBUTE(x)
#define	WT_GCC_FUNC_DECL_ATTRIBUTE(x)

#define	WT_ATOMIC_FUNC(name, ret, type)					\
static inline ret							\
__wt_atomic_add##name(type *vp, type v)					\
{									\
	*vp += v;							\
	return (*vp);							\
}									\
static inline ret							\
__wt_atomic_fetch_add##name(type *vp, type v)				\
{									\
	type orig;							\
									\
	old = *vp;							\
	*vp += v;							\
	return (old);							\
}									\
static inline ret							\
__wt_atomic_store##name(type *vp, type v)				\
{									\
	type orig;							\
									\
	orig = *vp;							\
	*vp = v;							\
	return (old);							\
}									\
static inline ret							\
__wt_atomic_sub##name(type *vp, type v)					\
{									\
	*vp -= v;							\
	return (*vp);							\
}									\
static inline int							\
__wt_atomic_cas##name(type *vp, type old, type new)			\
{									\
	if (*vp == old) {						\
		*vp = new;						\
		return (1);						\
	}								\
	return (0);							\
}

WT_ATOMIC_FUNC(1, uint8_t, uint8_t)
WT_ATOMIC_FUNC(2, uint16_t, uint16_t)
WT_ATOMIC_FUNC(4, uint32_t, uint32_t)
WT_ATOMIC_FUNC(v4, uint32_t, volatile uint32_t)
WT_ATOMIC_FUNC(i4, int32_t, int32_t)
WT_ATOMIC_FUNC(iv4, int32_t, volatile int32_t)
WT_ATOMIC_FUNC(8, uint64_t, uint64_t)
WT_ATOMIC_FUNC(v8, uint64_t, volatile uint64_t)
WT_ATOMIC_FUNC(i8, int64_t, int64_t)
WT_ATOMIC_FUNC(iv8, int64_t, volatile int64_t)

/*
 * __wt_atomic_cas_ptr --
 *	Pointer compare and swap.
 */
static inline int
__wt_atomic_cas_ptr(void *vp, void *old, void *new) {
	if (*(void **)vp == old) {
		*(void **)vp = new;
		return (1);
	}
	return (0);
}

static inline void WT_BARRIER(void) { return; }
static inline void WT_FULL_BARRIER(void) { return; }
static inline void WT_PAUSE(void) { return; }
static inline void WT_READ_BARRIER(void) { return; }
static inline void WT_WRITE_BARRIER(void) { return; }