mirror of
https://github.com/golang/go.git
synced 2025-12-08 06:10:04 +00:00
[release-branch.go1.24] runtime/cgo: avoid errors from -Wdeclaration-after-statement
It's used by the SWIG CI build, at least, and it's an easy fix.
Fixes #71963
For #71961
Change-Id: Id21071a5aef216b35ecf0e9cd3e05d08972d92fe
Reviewed-on: https://go-review.googlesource.com/c/go/+/652181
Reviewed-by: Cherry Mui <cherryyz@google.com>
Reviewed-by: Michael Pratt <mpratt@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Auto-Submit: Michael Pratt <mpratt@google.com>
(cherry picked from commit 76c7028253)
Reviewed-on: https://go-review.googlesource.com/c/go/+/652936
Reviewed-by: Michael Knyszek <mknyszek@google.com>
This commit is contained in:
parent
7f375e2c22
commit
45a52718e3
3 changed files with 10 additions and 4 deletions
|
|
@ -25,7 +25,8 @@ package cgo
|
||||||
|
|
||||||
// Use -fno-stack-protector to avoid problems locating the
|
// Use -fno-stack-protector to avoid problems locating the
|
||||||
// proper support functions. See issues #52919, #54313, #58385.
|
// proper support functions. See issues #52919, #54313, #58385.
|
||||||
#cgo CFLAGS: -Wall -Werror -fno-stack-protector
|
// Use -Wdeclaration-after-statement because some CI builds use it.
|
||||||
|
#cgo CFLAGS: -Wall -Werror -fno-stack-protector -Wdeclaration-after-statement
|
||||||
|
|
||||||
#cgo solaris CPPFLAGS: -D_POSIX_PTHREAD_SEMANTICS
|
#cgo solaris CPPFLAGS: -D_POSIX_PTHREAD_SEMANTICS
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -39,10 +39,11 @@ void
|
||||||
x_cgo_sys_thread_create(void* (*func)(void*), void* arg) {
|
x_cgo_sys_thread_create(void* (*func)(void*), void* arg) {
|
||||||
pthread_attr_t attr;
|
pthread_attr_t attr;
|
||||||
pthread_t p;
|
pthread_t p;
|
||||||
|
int err;
|
||||||
|
|
||||||
pthread_attr_init(&attr);
|
pthread_attr_init(&attr);
|
||||||
pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED);
|
pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED);
|
||||||
int err = _cgo_try_pthread_create(&p, &attr, func, arg);
|
err = _cgo_try_pthread_create(&p, &attr, func, arg);
|
||||||
if (err != 0) {
|
if (err != 0) {
|
||||||
fprintf(stderr, "pthread_create failed: %s", strerror(err));
|
fprintf(stderr, "pthread_create failed: %s", strerror(err));
|
||||||
abort();
|
abort();
|
||||||
|
|
@ -52,9 +53,11 @@ x_cgo_sys_thread_create(void* (*func)(void*), void* arg) {
|
||||||
uintptr_t
|
uintptr_t
|
||||||
_cgo_wait_runtime_init_done(void) {
|
_cgo_wait_runtime_init_done(void) {
|
||||||
void (*pfn)(struct context_arg*);
|
void (*pfn)(struct context_arg*);
|
||||||
|
int done;
|
||||||
|
|
||||||
pfn = __atomic_load_n(&cgo_context_function, __ATOMIC_CONSUME);
|
pfn = __atomic_load_n(&cgo_context_function, __ATOMIC_CONSUME);
|
||||||
|
|
||||||
int done = 2;
|
done = 2;
|
||||||
if (__atomic_load_n(&runtime_init_done, __ATOMIC_CONSUME) != done) {
|
if (__atomic_load_n(&runtime_init_done, __ATOMIC_CONSUME) != done) {
|
||||||
pthread_mutex_lock(&runtime_init_mu);
|
pthread_mutex_lock(&runtime_init_mu);
|
||||||
while (__atomic_load_n(&runtime_init_done, __ATOMIC_CONSUME) == 0) {
|
while (__atomic_load_n(&runtime_init_done, __ATOMIC_CONSUME) == 0) {
|
||||||
|
|
|
||||||
|
|
@ -75,8 +75,10 @@ x_cgo_sys_thread_create(void (*func)(void*), void* arg) {
|
||||||
|
|
||||||
int
|
int
|
||||||
_cgo_is_runtime_initialized() {
|
_cgo_is_runtime_initialized() {
|
||||||
|
int status;
|
||||||
|
|
||||||
EnterCriticalSection(&runtime_init_cs);
|
EnterCriticalSection(&runtime_init_cs);
|
||||||
int status = runtime_init_done;
|
status = runtime_init_done;
|
||||||
LeaveCriticalSection(&runtime_init_cs);
|
LeaveCriticalSection(&runtime_init_cs);
|
||||||
return status;
|
return status;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue