summaryrefslogtreecommitdiffstats
path: root/include/sys/atomic.h
blob: 1f2a4780b51ea8e66bb73220e28d7f3781cf89e8 (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
#ifndef _SPL_ATOMIC_H
#define _SPL_ATOMIC_H

#ifdef  __cplusplus
extern "C" {
#endif

#include <linux/module.h>
/* FIXME - NONE OF THIS IS ATOMIC, IT SHOULD BE.  I think we can
 * get by for now since I'm only working on real 64bit systems but
 * this will need to be addressed properly.
 */

static __inline__ void
atomic_inc_64(volatile uint64_t *target)
{
	(*target)++;
}

static __inline__ void
atomic_dec_64(volatile uint64_t *target)
{
	(*target)--;
}

static __inline__ uint32_t
atomic_add_32(volatile uint32_t *target, int32_t delta)
{
	uint32_t rc = *target;
	*target += delta;
	return rc;
}

static __inline__ uint64_t
atomic_add_64(volatile uint64_t *target, uint64_t delta)
{
	uint64_t rc = *target;
	*target += delta;
	return rc;
}

static __inline__ uint64_t
atomic_add_64_nv(volatile uint64_t *target, uint64_t delta)
{
	*target += delta;
	return *target;
}

static __inline__ uint64_t
atomic_cas_64(volatile uint64_t  *target,  uint64_t cmp,
               uint64_t newval)
{
	uint64_t rc = *target;

	if (*target == cmp)
		*target = newval;

	return rc;
}

static __inline__ void *
atomic_cas_ptr(volatile void  *target,  void *cmp, void *newval)
{
	void *rc = (void *)target;

	if (target == cmp)
		target = newval;

	return rc;
}

#ifdef  __cplusplus
}
#endif

#endif  /* _SPL_ATOMIC_H */