Source file src/runtime/netpoll_stub.go

     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 "internal/runtime/atomic"
    10  
    11  var netpollInited atomic.Uint32
    12  
    13  var netpollStubLock mutex
    14  var netpollNote note
    15  
    16  // netpollBroken, protected by netpollBrokenLock, avoids a double notewakeup.
    17  var netpollBrokenLock mutex
    18  var netpollBroken bool
    19  
    20  func netpollGenericInit() {
    21  	netpollInited.Store(1)
    22  }
    23  
    24  func netpollBreak() {
    25  	lock(&netpollBrokenLock)
    26  	broken := netpollBroken
    27  	netpollBroken = true
    28  	if !broken {
    29  		notewakeup(&netpollNote)
    30  	}
    31  	unlock(&netpollBrokenLock)
    32  }
    33  
    34  // Polls for ready network connections.
    35  // Returns a list of goroutines that become runnable,
    36  // and a delta to add to netpollWaiters.
    37  // This must never return an empty list with a non-zero delta.
    38  func netpoll(delay int64) (gList, int32) {
    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{}, 0
    58  }
    59  
    60  func netpollinited() bool {
    61  	return netpollInited.Load() != 0
    62  }
    63  
    64  func netpollAnyWaiters() bool {
    65  	return false
    66  }
    67  
    68  func netpollAdjustWaiters(delta int32) {
    69  }
    70  

View as plain text