aboutsummaryrefslogtreecommitdiff
path: root/src/pkg/runtime/runtime.c
diff options
context:
space:
mode:
authorDmitriy Vyukov <dvyukov@google.com>2012-04-05 18:47:43 +0400
committerDmitriy Vyukov <dvyukov@google.com>2012-04-05 18:47:43 +0400
commit4667571619fbbb7bf01699388432685dbec8fc9f (patch)
tree7047f6e35e45e89a2a4b19f9c52944388d53536d /src/pkg/runtime/runtime.c
parenta28a10e1a2352736fa8bbf6def02517f42260e34 (diff)
downloadgo-4667571619fbbb7bf01699388432685dbec8fc9f.tar.xz
runtime: add 64-bit atomics
This is factored out part of: https://golang.org/cl/5279048/ (Parallel GC) R=golang-dev, rsc CC=golang-dev https://golang.org/cl/5985047
Diffstat (limited to 'src/pkg/runtime/runtime.c')
-rw-r--r--src/pkg/runtime/runtime.c30
1 files changed, 30 insertions, 0 deletions
diff --git a/src/pkg/runtime/runtime.c b/src/pkg/runtime/runtime.c
index ebb5544fba..2cb3501dd1 100644
--- a/src/pkg/runtime/runtime.c
+++ b/src/pkg/runtime/runtime.c
@@ -4,6 +4,7 @@
#include "runtime.h"
#include "stack.h"
+#include "arch_GOARCH.h"
enum {
maxround = sizeof(uintptr),
@@ -267,6 +268,33 @@ runtime·atoi(byte *p)
return n;
}
+static void
+TestAtomic64(void)
+{
+ uint64 z64, x64;
+
+ z64 = 42;
+ x64 = 0;
+ PREFETCH(&z64);
+ if(runtime·cas64(&z64, &x64, 1))
+ runtime·throw("cas64 failed");
+ if(x64 != 42)
+ runtime·throw("cas64 failed");
+ if(!runtime·cas64(&z64, &x64, 1))
+ runtime·throw("cas64 failed");
+ if(x64 != 42 || z64 != 1)
+ runtime·throw("cas64 failed");
+ if(runtime·atomicload64(&z64) != 1)
+ runtime·throw("load64 failed");
+ runtime·atomicstore64(&z64, (1ull<<40)+1);
+ if(runtime·atomicload64(&z64) != (1ull<<40)+1)
+ runtime·throw("store64 failed");
+ if(runtime·xadd64(&z64, (1ull<<40)+1) != (2ull<<40)+2)
+ runtime·throw("xadd64 failed");
+ if(runtime·atomicload64(&z64) != (2ull<<40)+2)
+ runtime·throw("xadd64 failed");
+}
+
void
runtime·check(void)
{
@@ -342,6 +370,8 @@ runtime·check(void)
runtime·throw("float32nan2");
if(!(i != i1))
runtime·throw("float32nan3");
+
+ TestAtomic64();
}
void