Skip to content

Commit c7b2f64

Browse files
committed
runtime: clarify Pinner doc
Rewrite in idiomatic form, fix a typo, break into paragraph, rephrase slightly. Change-Id: If146db86aa84214e61128a3bc3e9905396d44710 Reviewed-on: https://go-review.googlesource.com/c/go/+/498716 TryBot-Result: Gopher Robot <[email protected]> Run-TryBot: Jonathan Amsterdam <[email protected]> Reviewed-by: Ansiwen <[email protected]> Reviewed-by: Ian Lance Taylor <[email protected]> Reviewed-by: Michael Knyszek <[email protected]>
1 parent 5ad676a commit c7b2f64

File tree

1 file changed

+12
-8
lines changed

1 file changed

+12
-8
lines changed

src/runtime/pinner.go

+12-8
Original file line numberDiff line numberDiff line change
@@ -9,21 +9,25 @@ import (
99
"unsafe"
1010
)
1111

12-
// Pinner represents a set of pinned Go objects. An object can be pinned with
12+
// A Pinner is a set of pinned Go objects. An object can be pinned with
1313
// the Pin method and all pinned objects of a Pinner can be unpinned with the
1414
// Unpin method.
1515
type Pinner struct {
1616
*pinner
1717
}
1818

19-
// Pin a Go object. The object will not be moved or freed by the garbage
20-
// collector until the Unpin method has been called. The pointer to a pinned
19+
// Pin pins a Go object, preventing it from being moved or freed by the garbage
20+
// collector until the Unpin method has been called.
21+
//
22+
// A pointer to a pinned
2123
// object can be directly stored in C memory or can be contained in Go memory
22-
// passed to C functions. If the pinned object iftself contains pointers to Go
24+
// passed to C functions. If the pinned object itself contains pointers to Go
2325
// objects, these objects must be pinned separately if they are going to be
24-
// accessed from C code. The argument must be a pointer of any type or an
25-
// unsafe.Pointer. It must be a pointer to an object allocated by calling new,
26-
// by taking the address of a composite literal, or by taking the address of a
26+
// accessed from C code.
27+
//
28+
// The argument must be a pointer of any type or an
29+
// unsafe.Pointer. It must be the result of calling new,
30+
// taking the address of a composite literal, or taking the address of a
2731
// local variable. If one of these conditions is not met, Pin will panic.
2832
func (p *Pinner) Pin(pointer any) {
2933
if p.pinner == nil {
@@ -59,7 +63,7 @@ func (p *Pinner) Pin(pointer any) {
5963
p.refs = append(p.refs, ptr)
6064
}
6165

62-
// Unpin all pinned objects of the Pinner.
66+
// Unpin unpins all pinned objects of the Pinner.
6367
func (p *Pinner) Unpin() {
6468
p.pinner.unpin()
6569

0 commit comments

Comments
 (0)