mirror of https://bitbucket.org/ausocean/av.git
Created IsWritable function and also changed name of CanRead() to IsReadable()
This commit is contained in:
parent
13c6bd531b
commit
382d83c701
ringbuffer
|
@ -81,7 +81,7 @@ a call to Get without an accompanying call to DoneWriting.
|
|||
func (rb *ringBuffer) Get() ([]byte, error) {
|
||||
rb.mutex.Lock()
|
||||
defer rb.mutex.Unlock()
|
||||
if rb.noOfElements == rb.size {
|
||||
if !rb.IsWritable() {
|
||||
return nil, errors.New("Buffer full!")
|
||||
}
|
||||
if rb.currentlyWriting {
|
||||
|
@ -129,7 +129,7 @@ second call to Read before a call to DoneReading.
|
|||
func (rb *ringBuffer) Read() ([]byte, error) {
|
||||
rb.mutex.Lock()
|
||||
defer rb.mutex.Unlock()
|
||||
if !rb.CanRead() {
|
||||
if !rb.IsReadable() {
|
||||
return nil, errors.New("Buffer is empty, nothging to read!")
|
||||
}
|
||||
if rb.currentlyReading {
|
||||
|
@ -160,12 +160,23 @@ func (rb *ringBuffer) DoneReading() error {
|
|||
}
|
||||
|
||||
/*
|
||||
CanRead returns true if it is possible to read from the buffer, i.e. if
|
||||
IsReadable returns true if it is possible to read from the buffer, i.e. if
|
||||
it is not empty.
|
||||
*/
|
||||
func (rb *ringBuffer) CanRead() bool {
|
||||
func (rb *ringBuffer) IsReadable() bool {
|
||||
if rb.first == -1 || rb.noOfElements == 0 {
|
||||
return false
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
/*
|
||||
IsWritable returns true if it is possible to write to the buffer, i.e. if
|
||||
it is not full.
|
||||
*/
|
||||
func (rb *ringBuffer) IsWritable() bool {
|
||||
if rb.noOfElements == rb.size {
|
||||
return false
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue