Skip to content

Commit 2681efa

Browse files
os/signal, runtime: remove runtime sigqueue initialization
We can initialize the runtime sigqueue packages on first use. We don't require an explicit initialization step. So, remove it. Change-Id: I484e02dc2c67395fd5584f35ecda2e28b37168df Reviewed-on: https://go-review.googlesource.com/c/go/+/226540 Run-TryBot: Ian Lance Taylor <[email protected]> Reviewed-by: Bryan C. Mills <[email protected]>
1 parent 6202087 commit 2681efa

File tree

5 files changed

+13
-21
lines changed

5 files changed

+13
-21
lines changed

src/os/signal/signal.go

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -122,12 +122,6 @@ func Notify(c chan<- os.Signal, sig ...os.Signal) {
122122
panic("os/signal: Notify using nil channel")
123123
}
124124

125-
watchSignalLoopOnce.Do(func() {
126-
if watchSignalLoop != nil {
127-
go watchSignalLoop()
128-
}
129-
})
130-
131125
handlers.Lock()
132126
defer handlers.Unlock()
133127

@@ -148,6 +142,14 @@ func Notify(c chan<- os.Signal, sig ...os.Signal) {
148142
h.set(n)
149143
if handlers.ref[n] == 0 {
150144
enableSignal(n)
145+
146+
// The runtime requires that we enable a
147+
// signal before starting the watcher.
148+
watchSignalLoopOnce.Do(func() {
149+
if watchSignalLoop != nil {
150+
go watchSignalLoop()
151+
}
152+
})
151153
}
152154
handlers.ref[n]++
153155
}

src/os/signal/signal_plan9.go

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,16 +11,14 @@ import (
1111

1212
var sigtab = make(map[os.Signal]int)
1313

14-
// In sig.s; jumps to runtime.
14+
// Defined by the runtime package.
1515
func signal_disable(uint32)
1616
func signal_enable(uint32)
1717
func signal_ignore(uint32)
1818
func signal_ignored(uint32) bool
1919
func signal_recv() string
2020

2121
func init() {
22-
signal_enable(0) // first call - initialize
23-
2422
watchSignalLoop = loop
2523
}
2624

src/os/signal/signal_unix.go

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,6 @@ func loop() {
2525
}
2626

2727
func init() {
28-
signal_enable(0) // first call - initialize
29-
3028
watchSignalLoop = loop
3129
}
3230

src/runtime/sigqueue.go

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -192,16 +192,13 @@ func signalWaitUntilIdle() {
192192
//go:linkname signal_enable os/signal.signal_enable
193193
func signal_enable(s uint32) {
194194
if !sig.inuse {
195-
// The first call to signal_enable is for us
196-
// to use for initialization. It does not pass
197-
// signal information in m.
195+
// This is the first call to signal_enable. Initialize.
198196
sig.inuse = true // enable reception of signals; cannot disable
199197
if GOOS == "darwin" {
200198
sigNoteSetup(&sig.note)
201-
return
199+
} else {
200+
noteclear(&sig.note)
202201
}
203-
noteclear(&sig.note)
204-
return
205202
}
206203

207204
if s >= uint32(len(sig.wanted)*32) {

src/runtime/sigqueue_plan9.go

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -134,12 +134,9 @@ func signalWaitUntilIdle() {
134134
//go:linkname signal_enable os/signal.signal_enable
135135
func signal_enable(s uint32) {
136136
if !sig.inuse {
137-
// The first call to signal_enable is for us
138-
// to use for initialization. It does not pass
139-
// signal information in m.
137+
// This is the first call to signal_enable. Initialize.
140138
sig.inuse = true // enable reception of signals; cannot disable
141139
noteclear(&sig.note)
142-
return
143140
}
144141
}
145142

0 commit comments

Comments
 (0)