From ce7283ae1b180452558bd5563e6c7aef52b1a4bd Mon Sep 17 00:00:00 2001 From: Matthew Jaffee Date: Tue, 19 Sep 2017 15:52:42 -0500 Subject: [PATCH] convert to RWMutex in index, holder, view, and frame use RLock and RUnlock in mapperLocal hotpath --- frame.go | 10 +++++----- holder.go | 6 +++--- index.go | 6 +++--- view.go | 6 +++--- 4 files changed, 14 insertions(+), 14 deletions(-) diff --git a/frame.go b/frame.go index f9580cc6b..2fcb0c47d 100644 --- a/frame.go +++ b/frame.go @@ -43,7 +43,7 @@ const ( // Frame represents a container for views. type Frame struct { - mu sync.Mutex + mu sync.RWMutex path string index string name string @@ -404,8 +404,8 @@ func (f *Frame) Close() error { // Schema returns the frame's current schema. func (f *Frame) Schema() *FrameSchema { - f.mu.Lock() - defer f.mu.Unlock() + f.mu.RLock() + defer f.mu.RUnlock() return f.schema } @@ -506,8 +506,8 @@ func (f *Frame) ViewPath(name string) string { // View returns a view in the frame by name. func (f *Frame) View(name string) *View { - f.mu.Lock() - defer f.mu.Unlock() + f.mu.RLock() + defer f.mu.RUnlock() return f.view(name) } diff --git a/holder.go b/holder.go index 4270c2594..0cf5f6901 100644 --- a/holder.go +++ b/holder.go @@ -38,7 +38,7 @@ const ( // Holder represents a container for indexes. type Holder struct { - mu sync.Mutex + mu sync.RWMutex // Indexes by name. indexes map[string]*Index @@ -183,8 +183,8 @@ func (h *Holder) IndexPath(name string) string { return filepath.Join(h.Path, na // Index returns the index by name. func (h *Holder) Index(name string) *Index { - h.mu.Lock() - defer h.mu.Unlock() + h.mu.RLock() + defer h.mu.RUnlock() return h.index(name) } diff --git a/index.go b/index.go index 345215690..5c7e06f05 100644 --- a/index.go +++ b/index.go @@ -37,7 +37,7 @@ const ( // Index represents a container for frames. type Index struct { - mu sync.Mutex + mu sync.RWMutex path string name string @@ -345,8 +345,8 @@ func (i *Index) InputDefinitionPath() string { // Frame returns a frame in the index by name. func (i *Index) Frame(name string) *Frame { - i.mu.Lock() - defer i.mu.Unlock() + i.mu.RLock() + defer i.mu.RUnlock() return i.frame(name) } diff --git a/view.go b/view.go index 2d5b7d776..3f5a61437 100644 --- a/view.go +++ b/view.go @@ -43,7 +43,7 @@ func IsValidView(name string) bool { // View represents a container for frame data. type View struct { - mu sync.Mutex + mu sync.RWMutex path string index string frame string @@ -194,8 +194,8 @@ func (v *View) FragmentPath(slice uint64) string { // Fragment returns a fragment in the view by slice. func (v *View) Fragment(slice uint64) *Fragment { - v.mu.Lock() - defer v.mu.Unlock() + v.mu.RLock() + defer v.mu.RUnlock() return v.fragment(slice) }