1
0
mirror of https://github.com/v2fly/v2ray-core.git synced 2024-12-22 10:08:15 -05:00

remove lock on bytes reader and writer

This commit is contained in:
Darien Raymond 2016-12-27 20:53:29 +01:00
parent f195f15536
commit ea33b7691b
No known key found for this signature in database
GPG Key ID: 7251FFA14BB18169
2 changed files with 2 additions and 25 deletions

View File

@ -1,9 +1,6 @@
package buf
import (
"io"
"sync"
)
import "io"
// BytesToBufferReader is a Reader that adjusts its reading speed automatically.
type BytesToBufferReader struct {
@ -52,7 +49,6 @@ func (v *BytesToBufferReader) Release() {
}
type BufferToBytesReader struct {
sync.Mutex
stream Reader
current *Buffer
eof bool
@ -74,8 +70,6 @@ func (v *BufferToBytesReader) Read(b []byte) (int, error) {
return 0, io.EOF
}
v.Lock()
defer v.Unlock()
if v.current == nil {
v.Fill()
if v.eof {
@ -92,11 +86,7 @@ func (v *BufferToBytesReader) Read(b []byte) (int, error) {
// Release implements Releasable.Release().
func (v *BufferToBytesReader) Release() {
v.Lock()
defer v.Unlock()
v.eof = true
v.current.Release()
v.current = nil
v.stream = nil
}

View File

@ -1,9 +1,6 @@
package buf
import (
"io"
"sync"
)
import "io"
// BufferToBytesWriter is a Writer that writes alloc.Buffer into underlying writer.
type BufferToBytesWriter struct {
@ -32,17 +29,10 @@ func (v *BufferToBytesWriter) Release() {
}
type BytesToBufferWriter struct {
sync.Mutex
writer Writer
}
func (v *BytesToBufferWriter) Write(payload []byte) (int, error) {
v.Lock()
defer v.Unlock()
if v.writer == nil {
return 0, io.ErrClosedPipe
}
bytesWritten := 0
size := len(payload)
for size > 0 {
@ -62,8 +52,5 @@ func (v *BytesToBufferWriter) Write(payload []byte) (int, error) {
// Release implements Releasable.Release()
func (v *BytesToBufferWriter) Release() {
v.Lock()
v.writer.Release()
v.writer = nil
v.Unlock()
}