summaryrefslogtreecommitdiffhomepage
path: root/pkg/tcpip/link/qdisc/fifo
diff options
context:
space:
mode:
authorAdin Scannell <ascannell@google.com>2021-11-04 18:50:20 -0700
committergVisor bot <gvisor-bot@google.com>2021-11-04 18:53:15 -0700
commitd80af5f8b58d2bfe23d57e133a8d35eaed59fa13 (patch)
tree31d00204bdd4be118ddc5409ad1155b78c196938 /pkg/tcpip/link/qdisc/fifo
parentfe8e48fc6d5094fe34783b1040b2ae4ba05349b5 (diff)
Remove id from sleep.Sleeper API.
In a subsequent change, the Sleeper API will be plumbed through and used for arbitrary task wakeups. This requires a non-static association of Wakers and Sleepers, which means that a fixed ID no longer works. This is a relatively simple change that removes the ID from the Waker association, and simply uses the Waker pointer itself. That change also makes minor improvements to the tests to ensure that the benchmarks are more representative by removing goroutine start from the hot path (and uses Wakers for required synchronization), adds assertion checks to AddWaker, and clears relevant fields during Done (to allow assertions to pass). PiperOrigin-RevId: 407719630
Diffstat (limited to 'pkg/tcpip/link/qdisc/fifo')
-rw-r--r--pkg/tcpip/link/qdisc/fifo/endpoint.go11
1 files changed, 5 insertions, 6 deletions
diff --git a/pkg/tcpip/link/qdisc/fifo/endpoint.go b/pkg/tcpip/link/qdisc/fifo/endpoint.go
index b41e3e2fa..c15cbf81b 100644
--- a/pkg/tcpip/link/qdisc/fifo/endpoint.go
+++ b/pkg/tcpip/link/qdisc/fifo/endpoint.go
@@ -73,20 +73,19 @@ func New(lower stack.LinkEndpoint, n int, queueLen int) stack.LinkEndpoint {
}
func (q *queueDispatcher) dispatchLoop() {
- const newPacketWakerID = 1
- const closeWakerID = 2
s := sleep.Sleeper{}
- s.AddWaker(&q.newPacketWaker, newPacketWakerID)
- s.AddWaker(&q.closeWaker, closeWakerID)
+ s.AddWaker(&q.newPacketWaker)
+ s.AddWaker(&q.closeWaker)
defer s.Done()
const batchSize = 32
var batch stack.PacketBufferList
for {
- id, ok := s.Fetch(true)
- if ok && id == closeWakerID {
+ w := s.Fetch(true)
+ if w == &q.closeWaker {
return
}
+ // Must otherwise be the newPacketWaker.
for pkt := q.q.dequeue(); pkt != nil; pkt = q.q.dequeue() {
batch.PushBack(pkt)
if batch.Len() < batchSize && !q.q.empty() {