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