summaryrefslogtreecommitdiff
path: root/misc/cgo/testtls/tls.go
diff options
context:
space:
mode:
authorMichael Stapelberg <stapelberg@debian.org>2013-05-14 18:39:35 +0200
committerMichael Stapelberg <michael@stapelberg.de>2013-05-14 18:39:35 +0200
commitefcc50dfdc94c82ee0292bf71992ecb7c0123061 (patch)
tree17dca99d1dc7fc4e9fe49c2cf6a99d337d4c039f /misc/cgo/testtls/tls.go
parent04b08da9af0c450d645ab7389d1467308cfc2db8 (diff)
downloadgolang-efcc50dfdc94c82ee0292bf71992ecb7c0123061.tar.gz
Imported Upstream version 1.1upstream/1.1
Diffstat (limited to 'misc/cgo/testtls/tls.go')
-rw-r--r--misc/cgo/testtls/tls.go28
1 files changed, 28 insertions, 0 deletions
diff --git a/misc/cgo/testtls/tls.go b/misc/cgo/testtls/tls.go
new file mode 100644
index 000000000..a9546a61c
--- /dev/null
+++ b/misc/cgo/testtls/tls.go
@@ -0,0 +1,28 @@
+// Copyright 2013 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.
+
+package cgotlstest
+
+// #include <pthread.h>
+// extern void setTLS(int);
+// extern int getTLS();
+import "C"
+
+import (
+ "runtime"
+ "testing"
+)
+
+func testTLS(t *testing.T) {
+ var keyVal C.int = 1234
+
+ runtime.LockOSThread()
+ defer runtime.UnlockOSThread()
+ C.setTLS(C.int(keyVal))
+ storedVal := C.getTLS()
+
+ if storedVal != keyVal {
+ t.Fatalf("stored %d want %d", storedVal, keyVal)
+ }
+}