]> Cypherpunks repositories - gostls13.git/commitdiff
os/signal, runtime: remove runtime sigqueue initialization
authorIan Lance Taylor <iant@golang.org>
Tue, 31 Mar 2020 17:49:31 +0000 (10:49 -0700)
committerIan Lance Taylor <iant@golang.org>
Wed, 1 Apr 2020 23:55:34 +0000 (23:55 +0000)
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 <iant@golang.org>
Reviewed-by: Bryan C. Mills <bcmills@google.com>
src/os/signal/signal.go
src/os/signal/signal_plan9.go
src/os/signal/signal_unix.go
src/runtime/sigqueue.go
src/runtime/sigqueue_plan9.go

index 136dd9cc97f504b19ebd24ed2e2dc88e0e93cde5..8e31aa26278b12be75bc32752c2b818ec902af69 100644 (file)
@@ -122,12 +122,6 @@ func Notify(c chan<- os.Signal, sig ...os.Signal) {
                panic("os/signal: Notify using nil channel")
        }
 
-       watchSignalLoopOnce.Do(func() {
-               if watchSignalLoop != nil {
-                       go watchSignalLoop()
-               }
-       })
-
        handlers.Lock()
        defer handlers.Unlock()
 
@@ -148,6 +142,14 @@ func Notify(c chan<- os.Signal, sig ...os.Signal) {
                        h.set(n)
                        if handlers.ref[n] == 0 {
                                enableSignal(n)
+
+                               // The runtime requires that we enable a
+                               // signal before starting the watcher.
+                               watchSignalLoopOnce.Do(func() {
+                                       if watchSignalLoop != nil {
+                                               go watchSignalLoop()
+                                       }
+                               })
                        }
                        handlers.ref[n]++
                }
index 8408607c7fa37879dc65de03e3ce496b8781b699..7d4871518a28fa201d58e96373f541724e3652aa 100644 (file)
@@ -11,7 +11,7 @@ import (
 
 var sigtab = make(map[os.Signal]int)
 
-// In sig.s; jumps to runtime.
+// Defined by the runtime package.
 func signal_disable(uint32)
 func signal_enable(uint32)
 func signal_ignore(uint32)
@@ -19,8 +19,6 @@ func signal_ignored(uint32) bool
 func signal_recv() string
 
 func init() {
-       signal_enable(0) // first call - initialize
-
        watchSignalLoop = loop
 }
 
index 89ee2d9e1856927a436b72575f053344e9a47d8f..90a1eca156fad726a5ddc0aef70560d2b0eda0fc 100644 (file)
@@ -25,8 +25,6 @@ func loop() {
 }
 
 func init() {
-       signal_enable(0) // first call - initialize
-
        watchSignalLoop = loop
 }
 
index b2ebb2b4574f17030ac0ca60297d3f290d304c61..3bf07cb5a6c42f5c6ff820cbba4b57a230f70ba9 100644 (file)
@@ -192,16 +192,13 @@ func signalWaitUntilIdle() {
 //go:linkname signal_enable os/signal.signal_enable
 func signal_enable(s uint32) {
        if !sig.inuse {
-               // The first call to signal_enable is for us
-               // to use for initialization. It does not pass
-               // signal information in m.
+               // This is the first call to signal_enable. Initialize.
                sig.inuse = true // enable reception of signals; cannot disable
                if GOOS == "darwin" {
                        sigNoteSetup(&sig.note)
-                       return
+               } else {
+                       noteclear(&sig.note)
                }
-               noteclear(&sig.note)
-               return
        }
 
        if s >= uint32(len(sig.wanted)*32) {
index 934742a1f4ceea509586044bb788a365376cd3e5..d5fe8f8b35df83f483d3c39a74acb63243f4062c 100644 (file)
@@ -134,12 +134,9 @@ func signalWaitUntilIdle() {
 //go:linkname signal_enable os/signal.signal_enable
 func signal_enable(s uint32) {
        if !sig.inuse {
-               // The first call to signal_enable is for us
-               // to use for initialization. It does not pass
-               // signal information in m.
+               // This is the first call to signal_enable. Initialize.
                sig.inuse = true // enable reception of signals; cannot disable
                noteclear(&sig.note)
-               return
        }
 }