Unverified Commit 67e9bf6d authored by Marten Seemann's avatar Marten Seemann Committed by GitHub

Merge pull request #42 from libp2p/remove-recv-lock

remove the recvLock in the stream
parents 4e665e89 5432a246
...@@ -37,8 +37,7 @@ type Stream struct { ...@@ -37,8 +37,7 @@ type Stream struct {
writeState, readState halfStreamState writeState, readState halfStreamState
stateLock sync.Mutex stateLock sync.Mutex
recvLock sync.Mutex recvBuf segmentedBuffer
recvBuf segmentedBuffer
recvNotifyCh chan struct{} recvNotifyCh chan struct{}
sendNotifyCh chan struct{} sendNotifyCh chan struct{}
...@@ -97,9 +96,7 @@ START: ...@@ -97,9 +96,7 @@ START:
} }
// If there is no data available, block // If there is no data available, block
s.recvLock.Lock()
if s.recvBuf.Len() == 0 { if s.recvBuf.Len() == 0 {
s.recvLock.Unlock()
select { select {
case <-s.recvNotifyCh: case <-s.recvNotifyCh:
goto START goto START
...@@ -110,7 +107,6 @@ START: ...@@ -110,7 +107,6 @@ START:
// Read any bytes // Read any bytes
n, _ = s.recvBuf.Read(b) n, _ = s.recvBuf.Read(b)
s.recvLock.Unlock()
// Send a window update potentially // Send a window update potentially
err = s.sendWindowUpdate() err = s.sendWindowUpdate()
...@@ -437,7 +433,7 @@ func (s *Stream) readData(hdr header, flags uint16, conn io.Reader) error { ...@@ -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) s.session.logger.Printf("[ERR] yamux: Failed to read stream data: %v", err)
return err return err
} }
// Unblock any readers // Unblock the reader
asyncNotify(s.recvNotifyCh) asyncNotify(s.recvNotifyCh)
return nil return nil
} }
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment