From 96d52f25b09fae789adb0c97ccf36f343a8f08fc Mon Sep 17 00:00:00 2001 From: Emir Beganovic Date: Sun, 14 Apr 2019 12:41:14 +0400 Subject: [PATCH] Use RWMutex --- main.go | 2 +- model_struct.go | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/main.go b/main.go index cc8ac68c..16820353 100644 --- a/main.go +++ b/main.go @@ -12,7 +12,7 @@ import ( // DB contains information for current db connection type DB struct { - sync.Mutex + sync.RWMutex Value interface{} Error error RowsAffected int64 diff --git a/model_struct.go b/model_struct.go index 8d6313fb..bfab49c0 100644 --- a/model_struct.go +++ b/model_struct.go @@ -40,11 +40,11 @@ func (s *ModelStruct) TableName(db *DB) string { s.defaultTableName = tabler.TableName() } else { tableName := ToTableName(s.ModelType.Name()) - db.parent.Lock() + db.parent.RLock() if db == nil || (db.parent != nil && !db.parent.singularTable) { tableName = inflection.Plural(tableName) } - db.parent.Unlock() + db.parent.RUnlock() s.defaultTableName = tableName } } @@ -167,9 +167,9 @@ func (scope *Scope) GetModelStruct() *ModelStruct { // Get Cached model struct isSingularTable := false if scope.db != nil && scope.db.parent != nil { - scope.db.parent.Lock() + scope.db.parent.RLock() isSingularTable = scope.db.parent.singularTable - scope.db.parent.Unlock() + scope.db.parent.RUnlock() } hashKey := struct {