2013-07-16 06:54:42 +00:00
|
|
|
// Copyright 2013 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.
|
|
|
|
|
2021-07-30 14:28:58 -07:00
|
|
|
//go:build plan9
|
2013-07-16 06:54:42 +00:00
|
|
|
|
2016-10-18 14:38:29 +00:00
|
|
|
package runtime
|
2013-07-16 06:54:42 +00:00
|
|
|
|
2020-01-02 15:05:27 -08:00
|
|
|
import "runtime/internal/atomic"
|
|
|
|
|
|
|
|
var netpollInited uint32
|
2017-09-14 17:11:35 +00:00
|
|
|
var netpollWaiters uint32
|
|
|
|
|
2020-01-02 15:05:27 -08:00
|
|
|
var netpollStubLock mutex
|
|
|
|
var netpollNote note
|
2020-02-26 11:15:50 -08:00
|
|
|
|
|
|
|
// netpollBroken, protected by netpollBrokenLock, avoids a double notewakeup.
|
|
|
|
var netpollBrokenLock mutex
|
|
|
|
var netpollBroken bool
|
2020-01-02 15:05:27 -08:00
|
|
|
|
|
|
|
func netpollGenericInit() {
|
|
|
|
atomic.Store(&netpollInited, 1)
|
|
|
|
}
|
|
|
|
|
|
|
|
func netpollBreak() {
|
2020-02-26 11:15:50 -08:00
|
|
|
lock(&netpollBrokenLock)
|
|
|
|
broken := netpollBroken
|
|
|
|
netpollBroken = true
|
|
|
|
if !broken {
|
2020-01-02 15:05:27 -08:00
|
|
|
notewakeup(&netpollNote)
|
|
|
|
}
|
2020-02-26 11:15:50 -08:00
|
|
|
unlock(&netpollBrokenLock)
|
2020-01-02 15:05:27 -08:00
|
|
|
}
|
|
|
|
|
2013-07-16 06:54:42 +00:00
|
|
|
// Polls for ready network connections.
|
|
|
|
// Returns list of goroutines that become runnable.
|
2020-01-02 15:05:27 -08:00
|
|
|
func netpoll(delay int64) gList {
|
2013-07-16 06:54:42 +00:00
|
|
|
// Implementation for platforms that do not support
|
|
|
|
// integrated network poller.
|
2020-01-02 15:05:27 -08:00
|
|
|
if delay != 0 {
|
|
|
|
// This lock ensures that only one goroutine tries to use
|
|
|
|
// the note. It should normally be completely uncontended.
|
|
|
|
lock(&netpollStubLock)
|
2020-02-26 11:15:50 -08:00
|
|
|
|
|
|
|
lock(&netpollBrokenLock)
|
2020-01-02 15:05:27 -08:00
|
|
|
noteclear(&netpollNote)
|
2020-02-26 11:15:50 -08:00
|
|
|
netpollBroken = false
|
|
|
|
unlock(&netpollBrokenLock)
|
|
|
|
|
2020-01-02 15:05:27 -08:00
|
|
|
notetsleep(&netpollNote, delay)
|
|
|
|
unlock(&netpollStubLock)
|
2020-07-27 22:27:54 -07:00
|
|
|
// Guard against starvation in case the lock is contended
|
|
|
|
// (eg when running TestNetpollBreak).
|
|
|
|
osyield()
|
2020-01-02 15:05:27 -08:00
|
|
|
}
|
2019-01-18 19:04:36 +00:00
|
|
|
return gList{}
|
2013-07-16 06:54:42 +00:00
|
|
|
}
|
2013-11-14 20:15:04 +00:00
|
|
|
|
2016-10-18 14:38:29 +00:00
|
|
|
func netpollinited() bool {
|
2020-01-02 15:05:27 -08:00
|
|
|
return atomic.Load(&netpollInited) != 0
|
2013-11-14 20:15:04 +00:00
|
|
|
}
|