| 1 |
// Copyright 2013 The Go Authors. All rights reserved. |
| 2 |
// Use of this source code is governed by a BSD-style |
| 3 |
// license that can be found in the LICENSE file. |
| 4 |
|
| 5 |
//go:build plan9 |
| 6 |
|
| 7 |
package runtime |
| 8 |
|
| 9 |
import "runtime/internal/atomic" |
| 10 |
|
| 11 |
var netpollInited uint32 |
| 12 |
var netpollWaiters uint32 |
| 13 |
|
| 14 |
var netpollStubLock mutex |
| 15 |
var netpollNote note |
| 16 |
|
| 17 |
// netpollBroken, protected by netpollBrokenLock, avoids a double notewakeup. |
| 18 |
var netpollBrokenLock mutex |
| 19 |
var netpollBroken bool |
| 20 |
|
| 21 |
func netpollGenericInit() { |
| 22 |
atomic.Store(&netpollInited, 1) |
| 23 |
} |
| 24 |
|
| 25 |
func netpollBreak() { |
| 26 |
lock(&netpollBrokenLock) |
| 27 |
broken := netpollBroken |
| 28 |
netpollBroken = true |
| 29 |
if !broken { |
| 30 |
notewakeup(&netpollNote) |
| 31 |
} |
| 32 |
unlock(&netpollBrokenLock) |
| 33 |
} |
| 34 |
|
| 35 |
// Polls for ready network connections. |
| 36 |
// Returns list of goroutines that become runnable. |
| 37 |
func netpoll(delay int64) gList { |
| 38 |
// Implementation for platforms that do not support |
| 39 |
// integrated network poller. |
| 40 |
if delay != 0 { |
| 41 |
// This lock ensures that only one goroutine tries to use |
| 42 |
// the note. It should normally be completely uncontended. |
| 43 |
lock(&netpollStubLock) |
| 44 |
|
| 45 |
lock(&netpollBrokenLock) |
| 46 |
noteclear(&netpollNote) |
| 47 |
netpollBroken = false |
| 48 |
unlock(&netpollBrokenLock) |
| 49 |
|
| 50 |
notetsleep(&netpollNote, delay) |
| 51 |
unlock(&netpollStubLock) |
| 52 |
// Guard against starvation in case the lock is contended |
| 53 |
// (eg when running TestNetpollBreak). |
| 54 |
osyield() |
| 55 |
} |
| 56 |
return gList{} |
| 57 |
} |
| 58 |
|
| 59 |
func netpollinited() bool { |
| 60 |
return atomic.Load(&netpollInited) != 0 |
| 61 |
} |