github.com/x04/go/src@v0.0.0-20200202162449-3d481ceb3525/runtime/netpoll_stub.go (about)

     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  
     7  package runtime
     8  
     9  import "github.com/x04/go/src/runtime/internal/atomic"
    10  
    11  var netpollInited uint32
    12  var netpollWaiters uint32
    13  
    14  var netpollStubLock mutex
    15  var netpollNote note
    16  var netpollBroken uint32
    17  
    18  func netpollGenericInit() {
    19  	atomic.Store(&netpollInited, 1)
    20  }
    21  
    22  func netpollBreak() {
    23  	if atomic.Cas(&netpollBroken, 0, 1) {
    24  		notewakeup(&netpollNote)
    25  	}
    26  }
    27  
    28  // Polls for ready network connections.
    29  // Returns list of goroutines that become runnable.
    30  func netpoll(delay int64) gList {
    31  	// Implementation for platforms that do not support
    32  	// integrated network poller.
    33  	if delay != 0 {
    34  		// This lock ensures that only one goroutine tries to use
    35  		// the note. It should normally be completely uncontended.
    36  		lock(&netpollStubLock)
    37  		noteclear(&netpollNote)
    38  		atomic.Store(&netpollBroken, 0)
    39  		notetsleep(&netpollNote, delay)
    40  		unlock(&netpollStubLock)
    41  	}
    42  	return gList{}
    43  }
    44  
    45  func netpollinited() bool {
    46  	return atomic.Load(&netpollInited) != 0
    47  }