Black Lives Matter. Support the Equal Justice Initiative.

Source file src/runtime/netpoll_stub.go

Documentation: runtime

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

View as plain text