mirror of https://github.com/golang/go.git
A non-trivial Cgo program may need to use callbacks and interact with go objects per goroutine. Because of the rules for passing pointers between Go and C, such a program needs to store handles to associated Go values. This often causes much extra effort to figure out a way to correctly deal with: 1) map collision; 2) identifying leaks and 3) concurrency. This CL implements a Handle representation in runtime/cgo package, and related methods such as Value, Delete, etc. which allows Go users can use a standard way to handle the above difficulties. In addition, the CL allows a Go value to have multiple handles, and the NewHandle always returns a different handle compare to the previously returned handles. In comparison, CL 294670 implements a different behavior of NewHandle that returns a unique handle when the Go value is referring to the same object. Benchmark: name time/op Handle/non-concurrent-16 487ns ± 1% Handle/concurrent-16 674ns ± 1% Fixes #37033 Change-Id: I0eadb9d44332fffef8fb567c745246a49dd6d4c1 Reviewed-on: https://go-review.googlesource.com/c/go/+/295369 Run-TryBot: Ian Lance Taylor <iant@golang.org> TryBot-Result: Go Bot <gobot@golang.org> Reviewed-by: Ian Lance Taylor <iant@golang.org> Trust: Cherry Zhang <cherryyz@google.com> |
||
|---|---|---|
| .. | ||
| testdata | ||
| backdoor.go | ||
| buildid_linux.go | ||
| callback.go | ||
| callback_c.c | ||
| callback_c_gc.c | ||
| callback_c_gccgo.c | ||
| cgo_linux_test.go | ||
| cgo_stubs_android_test.go | ||
| cgo_test.go | ||
| cgo_thread_lock.go | ||
| cgo_unix_test.go | ||
| cthread_unix.c | ||
| cthread_windows.c | ||
| issue1435.go | ||
| issue4029.c | ||
| issue4029.go | ||
| issue4029w.go | ||
| issue4273.c | ||
| issue4273b.c | ||
| issue4339.c | ||
| issue4339.h | ||
| issue5548_c.c | ||
| issue5740a.c | ||
| issue5740b.c | ||
| issue6833_c.c | ||
| issue6907export_c.c | ||
| issue6997_linux.c | ||
| issue6997_linux.go | ||
| issue7234_test.go | ||
| issue8148.go | ||
| issue8331.h | ||
| issue8517.go | ||
| issue8517_windows.c | ||
| issue8517_windows.go | ||
| issue8694.go | ||
| issue8811.c | ||
| issue18146.go | ||
| issue20910.c | ||
| issue21897.go | ||
| issue21897b.go | ||
| issue31891.c | ||
| issue42495.go | ||
| overlaydir_test.go | ||
| pkg_test.go | ||
| setgid_linux.go | ||
| sigaltstack.go | ||
| sigprocmask.c | ||
| sigprocmask.go | ||
| test.go | ||
| test_unix.go | ||
| test_windows.go | ||
| testx.go | ||