add rwmutex
This commit is contained in:
parent
6cc2c01268
commit
7668f44f97
@ -58,6 +58,7 @@ type Schema struct {
|
|||||||
initialized chan struct{}
|
initialized chan struct{}
|
||||||
namer Namer
|
namer Namer
|
||||||
cacheStore *sync.Map
|
cacheStore *sync.Map
|
||||||
|
rwmu sync.RWMutex
|
||||||
}
|
}
|
||||||
|
|
||||||
func (schema Schema) String() string {
|
func (schema Schema) String() string {
|
||||||
@ -76,6 +77,8 @@ func (schema Schema) MakeSlice() reflect.Value {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (schema Schema) LookUpField(name string) *Field {
|
func (schema Schema) LookUpField(name string) *Field {
|
||||||
|
schema.rwmu.RLock()
|
||||||
|
defer schema.rwmu.RUnlock()
|
||||||
if field, ok := schema.FieldsByDBName[name]; ok {
|
if field, ok := schema.FieldsByDBName[name]; ok {
|
||||||
return field
|
return field
|
||||||
}
|
}
|
||||||
@ -99,9 +102,12 @@ func (schema Schema) LookUpFieldByBindName(bindNames []string, name string) *Fie
|
|||||||
}
|
}
|
||||||
for i := len(bindNames) - 1; i >= 0; i-- {
|
for i := len(bindNames) - 1; i >= 0; i-- {
|
||||||
find := strings.Join(bindNames[:i], ".") + "." + name
|
find := strings.Join(bindNames[:i], ".") + "." + name
|
||||||
|
schema.rwmu.RLock()
|
||||||
if field, ok := schema.FieldsByBindName[find]; ok {
|
if field, ok := schema.FieldsByBindName[find]; ok {
|
||||||
|
schema.rwmu.RUnlock()
|
||||||
return field
|
return field
|
||||||
}
|
}
|
||||||
|
schema.rwmu.RUnlock()
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user