Skip to content

Commit

Permalink
Merge pull request #42 from libp2p/remove-recv-lock
Browse files Browse the repository at this point in the history
remove the recvLock in the stream
  • Loading branch information
marten-seemann authored Feb 17, 2021
2 parents 4e665e8 + 5432a24 commit 67e9bf6
Showing 1 changed file with 2 additions and 6 deletions.
8 changes: 2 additions & 6 deletions stream.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,7 @@ type Stream struct {
writeState, readState halfStreamState
stateLock sync.Mutex

recvLock sync.Mutex
recvBuf segmentedBuffer
recvBuf segmentedBuffer

recvNotifyCh chan struct{}
sendNotifyCh chan struct{}
Expand Down Expand Up @@ -97,9 +96,7 @@ START:
}

// If there is no data available, block
s.recvLock.Lock()
if s.recvBuf.Len() == 0 {
s.recvLock.Unlock()
select {
case <-s.recvNotifyCh:
goto START
Expand All @@ -110,7 +107,6 @@ START:

// Read any bytes
n, _ = s.recvBuf.Read(b)
s.recvLock.Unlock()

// Send a window update potentially
err = s.sendWindowUpdate()
Expand Down Expand Up @@ -437,7 +433,7 @@ func (s *Stream) readData(hdr header, flags uint16, conn io.Reader) error {
s.session.logger.Printf("[ERR] yamux: Failed to read stream data: %v", err)
return err
}
// Unblock any readers
// Unblock the reader
asyncNotify(s.recvNotifyCh)
return nil
}
Expand Down

0 comments on commit 67e9bf6

Please sign in to comment.