mirror of
https://github.com/golang/go
synced 2024-10-05 23:21:21 -06:00
e8694c8196
This is Part 2 of the change, see Part 1 here: in https://go-review.googlesource.com/#/c/7692/ Suggested by iant@, we use the library initialization entry point to: - create a new OS thread and run the "regular" runtime init stack on that thread - return immediately from the main (i.e., loader) thread - at the first CGO invocation, we wait for the runtime initialization to complete. The above mechanism is implemented only on linux_amd64. Next step is to support it on linux_arm. Other platforms don't yet support shared library compiling/linking, but we intend to use the same strategy there as well. Change-Id: Ib2c81b1b83bee837134084b75a3beecfb8de6bf4 Reviewed-on: https://go-review.googlesource.com/8094 Run-TryBot: Srdjan Petrovic <spetrovic@google.com> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Ian Lance Taylor <iant@golang.org>
35 lines
1.1 KiB
Go
35 lines
1.1 KiB
Go
// Copyright 2014 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 runtime
|
|
|
|
import "unsafe"
|
|
|
|
//go:cgo_export_static main
|
|
|
|
// Filled in by runtime/cgo when linked into binary.
|
|
|
|
//go:linkname _cgo_init _cgo_init
|
|
//go:linkname _cgo_malloc _cgo_malloc
|
|
//go:linkname _cgo_free _cgo_free
|
|
//go:linkname _cgo_thread_start _cgo_thread_start
|
|
//go:linkname _cgo_sys_thread_create _cgo_sys_thread_create
|
|
//go:linkname _cgo_notify_runtime_init_done _cgo_notify_runtime_init_done
|
|
|
|
var (
|
|
_cgo_init unsafe.Pointer
|
|
_cgo_malloc unsafe.Pointer
|
|
_cgo_free unsafe.Pointer
|
|
_cgo_thread_start unsafe.Pointer
|
|
_cgo_sys_thread_create unsafe.Pointer
|
|
_cgo_notify_runtime_init_done unsafe.Pointer
|
|
)
|
|
|
|
// iscgo is set to true by the runtime/cgo package
|
|
var iscgo bool
|
|
|
|
// cgoHasExtraM is set on startup when an extra M is created for cgo.
|
|
// The extra M must be created before any C/C++ code calls cgocallback.
|
|
var cgoHasExtraM bool
|