summaryrefslogtreecommitdiff
path: root/src/pkg/runtime/arm/atomic.c
blob: 52e4059ae210fb36bd56784ec24b650c7c97d5a8 (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
// Copyright 2009 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.

#include "runtime.h"

// Atomic add and return new value.
#pragma textflag 7
uint32
runtime·xadd(uint32 volatile *val, int32 delta)
{
	uint32 oval, nval;

	for(;;){
		oval = *val;
		nval = oval + delta;
		if(runtime·cas(val, oval, nval))
			return nval;
	}
}

#pragma textflag 7
uint32
runtime·xchg(uint32 volatile* addr, uint32 v)
{
	uint32 old;

	for(;;) {
		old = *addr;
		if(runtime·cas(addr, old, v))
			return old;
	}
}

#pragma textflag 7
void
runtime·procyield(uint32 cnt)
{
	uint32 volatile i;

	for(i = 0; i < cnt; i++) {
	}
}

#pragma textflag 7
uint32
runtime·atomicload(uint32 volatile* addr)
{
	return runtime·xadd(addr, 0);
}

#pragma textflag 7
void*
runtime·atomicloadp(void* volatile* addr)
{
	return (void*)runtime·xadd((uint32 volatile*)addr, 0);
}

#pragma textflag 7
void
runtime·atomicstorep(void* volatile* addr, void* v)
{
	void *old;

	for(;;) {
		old = *addr;
		if(runtime·casp(addr, old, v))
			return;
	}
}

#pragma textflag 7
void
runtime·atomicstore(uint32 volatile* addr, uint32 v)
{
	uint32 old;
	
	for(;;) {
		old = *addr;
		if(runtime·cas(addr, old, v))
			return;
	}
}