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// +build plan9
6
7package runtime
8
9import "runtime/internal/atomic"
10
11var netpollInited uint32
12var netpollWaiters uint32
13
14var netpollStubLock mutex
15var netpollNote note
16
17// netpollBroken, protected by netpollBrokenLock, avoids a double notewakeup.
18var netpollBrokenLock mutex
19var netpollBroken bool
20
21func netpollGenericInit() {
22	atomic.Store(&netpollInited, 1)
23}
24
25func 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.
37func 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	}
53	return gList{}
54}
55
56func netpollinited() bool {
57	return atomic.Load(&netpollInited) != 0
58}
59