From 73df946d56c74384511a194dd01dbe099584fd1a Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Sun, 28 Apr 2024 15:14:23 +0200 Subject: Adding upstream version 1.16.10. Signed-off-by: Daniel Baumann --- misc/cgo/testtls/tls.go | 30 ++++++++++++++++++++++++++++++ misc/cgo/testtls/tls_test.go | 13 +++++++++++++ misc/cgo/testtls/tls_unix.c | 19 +++++++++++++++++++ 3 files changed, 62 insertions(+) create mode 100644 misc/cgo/testtls/tls.go create mode 100644 misc/cgo/testtls/tls_test.go create mode 100644 misc/cgo/testtls/tls_unix.c (limited to 'misc/cgo/testtls') diff --git a/misc/cgo/testtls/tls.go b/misc/cgo/testtls/tls.go new file mode 100644 index 0000000..e634220 --- /dev/null +++ b/misc/cgo/testtls/tls.go @@ -0,0 +1,30 @@ +// 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 +// extern void setTLS(int); +// extern int getTLS(); +import "C" + +import ( + "runtime" + "testing" +) + +func testTLS(t *testing.T) { + runtime.LockOSThread() + defer runtime.UnlockOSThread() + + if val := C.getTLS(); val != 0 { + t.Fatalf("at start, C.getTLS() = %#x, want 0", val) + } + + const keyVal = 0x1234 + C.setTLS(keyVal) + if val := C.getTLS(); val != keyVal { + t.Fatalf("at end, C.getTLS() = %#x, want %#x", val, keyVal) + } +} diff --git a/misc/cgo/testtls/tls_test.go b/misc/cgo/testtls/tls_test.go new file mode 100644 index 0000000..3076c2d --- /dev/null +++ b/misc/cgo/testtls/tls_test.go @@ -0,0 +1,13 @@ +// 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. + +// +build !windows + +package cgotlstest + +import "testing" + +func TestTLS(t *testing.T) { + testTLS(t) +} diff --git a/misc/cgo/testtls/tls_unix.c b/misc/cgo/testtls/tls_unix.c new file mode 100644 index 0000000..957afce --- /dev/null +++ b/misc/cgo/testtls/tls_unix.c @@ -0,0 +1,19 @@ +// 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. + +#include + +static __thread int tls; + +void +setTLS(int v) +{ + tls = v; +} + +int +getTLS() +{ + return tls; +} -- cgit v1.2.3