mts: nonembeded mutex in TimeLocation

This commit is contained in:
saxon 2019-01-10 17:26:48 +10:30
parent 304d5501ac
commit 7fe8356b11
1 changed files with 13 additions and 11 deletions

View File

@ -127,37 +127,39 @@ const (
// timeLocation holds time and location data // timeLocation holds time and location data
type timeLocation struct { type timeLocation struct {
sync.RWMutex mu sync.RWMutex
time uint64 time uint64
location string location string
} }
// SetTimeStamp sets the time field of a TimeLocation. // SetTimeStamp sets the time field of a TimeLocation.
func (tl *timeLocation) SetTimeStamp(t uint64) { func (tl *timeLocation) SetTimeStamp(t uint64) {
tl.Lock() tl.mu.Lock()
tl.time = t tl.time = t
tl.Unlock() tl.mu.Unlock()
} }
// GetTimeStamp returns the location of a TimeLocation. // GetTimeStamp returns the location of a TimeLocation.
func (tl *timeLocation) TimeStamp() uint64 { func (tl *timeLocation) TimeStamp() uint64 {
tl.RLock() tl.mu.RLock()
defer tl.RUnlock() t := tl.time
return tl.time tl.mu.RUnlock()
return t
} }
// SetLocation sets the location of a TimeLocation. // SetLocation sets the location of a TimeLocation.
func (tl *timeLocation) SetLocation(l string) { func (tl *timeLocation) SetLocation(l string) {
tl.Lock() tl.mu.Lock()
tl.location = l tl.location = l
tl.Unlock() tl.mu.Unlock()
} }
// GetLocation returns the location of a TimeLocation. // GetLocation returns the location of a TimeLocation.
func (tl *timeLocation) Location() string { func (tl *timeLocation) Location() string {
tl.RLock() tl.mu.RLock()
defer tl.RUnlock() l := tl.location
return tl.location tl.mu.RUnlock()
return l
} }
// MetData will hold time and location data which may be set externally if // MetData will hold time and location data which may be set externally if