Use read-write lock instead of mutex (#2727)
This commit is contained in:
@@ -6,7 +6,7 @@ import "sync"
|
|||||||
type Ring struct {
|
type Ring struct {
|
||||||
elements []interface{}
|
elements []interface{}
|
||||||
index int
|
index int
|
||||||
lock sync.Mutex
|
lock sync.RWMutex
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewRing returns a Ring object with the given size n.
|
// NewRing returns a Ring object with the given size n.
|
||||||
@@ -31,8 +31,8 @@ func (r *Ring) Add(v interface{}) {
|
|||||||
|
|
||||||
// Take takes all items from r.
|
// Take takes all items from r.
|
||||||
func (r *Ring) Take() []interface{} {
|
func (r *Ring) Take() []interface{} {
|
||||||
r.lock.Lock()
|
r.lock.RLock()
|
||||||
defer r.lock.Unlock()
|
defer r.lock.RUnlock()
|
||||||
|
|
||||||
var size int
|
var size int
|
||||||
var start int
|
var start int
|
||||||
|
|||||||
Reference in New Issue
Block a user