Fix locking (#1141)
* Fix unprotected section * Optimize lock where only reads are performed
This commit is contained in:
parent
84a764ede2
commit
cabee7ab61
2 changed files with 4 additions and 5 deletions
|
@ -52,13 +52,12 @@ func (m *Files) Init() error {
|
|||
|
||||
// Done should be called after all files have been processed.
|
||||
func (m *Files) Done() {
|
||||
m.mutex.Lock()
|
||||
defer m.mutex.Unlock()
|
||||
if (len(m.files) - m.count) == 0 {
|
||||
return
|
||||
}
|
||||
|
||||
m.mutex.Lock()
|
||||
defer m.mutex.Unlock()
|
||||
|
||||
m.count = 0
|
||||
m.files = make(query.FileMap)
|
||||
}
|
||||
|
|
|
@ -61,8 +61,8 @@ func (m *Photos) Remove(takenAt time.Time, cellId string) {
|
|||
func (m *Photos) Find(takenAt time.Time, cellId string) uint {
|
||||
key := entity.MapKey(takenAt, cellId)
|
||||
|
||||
m.mutex.Lock()
|
||||
defer m.mutex.Unlock()
|
||||
m.mutex.RLock()
|
||||
defer m.mutex.RUnlock()
|
||||
|
||||
return m.photos[key]
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue