From 5b57025f802d2261ae9f3a1b518e173e0efdb644 Mon Sep 17 00:00:00 2001 From: Bo-Yi Wu Date: Sun, 3 May 2020 19:14:51 +0800 Subject: [PATCH] update Signed-off-by: Bo-Yi Wu --- context.go | 16 ++++------------ 1 file changed, 4 insertions(+), 12 deletions(-) diff --git a/context.go b/context.go index 0ae8b5bc..fb7f54e9 100644 --- a/context.go +++ b/context.go @@ -53,8 +53,6 @@ type Context struct { engine *Engine - EnableMutexLock bool - // This mutex protect Keys map mu sync.RWMutex @@ -235,27 +233,21 @@ func (c *Context) Error(err error) *Error { // Set is used to store a new key/value pair exclusively for this context. // It also lazy initializes c.Keys if it was not used previously. func (c *Context) Set(key string, value interface{}) { - if c.EnableMutexLock { - c.mu.Lock() - defer c.mu.Unlock() - } - + c.mu.Lock() if c.Keys == nil { c.Keys = make(map[string]interface{}) } c.Keys[key] = value + c.mu.Unlock() } // Get returns the value for the given key, ie: (value, true). // If the value does not exists it returns (nil, false) func (c *Context) Get(key string) (value interface{}, exists bool) { - if c.EnableMutexLock { - c.mu.RLock() - defer c.mu.RUnlock() - } - + c.mu.RLock() value, exists = c.Keys[key] + c.mu.RUnlock() return }