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 "runtime/internal/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 list of goroutines that become runnable.
    36  func netpoll(delay int64) (gList, int32) {
    37  	// Implementation for platforms that do not support
    38  	// integrated network poller.
    39  	if delay != 0 {
    40  		// This lock ensures that only one goroutine tries to use
    41  		// the note. It should normally be completely uncontended.
    42  		lock(&netpollStubLock)
    43  
    44  		lock(&netpollBrokenLock)
    45  		noteclear(&netpollNote)
    46  		netpollBroken = false
    47  		unlock(&netpollBrokenLock)
    48  
    49  		notetsleep(&netpollNote, delay)
    50  		unlock(&netpollStubLock)
    51  		// Guard against starvation in case the lock is contended
    52  		// (eg when running TestNetpollBreak).
    53  		osyield()
    54  	}
    55  	return gList{}, 0
    56  }
    57  
    58  func netpollinited() bool {
    59  	return netpollInited.Load() != 0
    60  }
    61  
    62  func netpollAnyWaiters() bool {
    63  	return false
    64  }
    65  
    66  func netpollAdjustWaiters(delta int32) {
    67  }
    68  

View as plain text