Skip to content

Take control over your live stream video by running it yourself. Streaming + chat out of the box.

Fix concurrent write crash. Fixes #578

Gabe Kangasa7337a722af7
diff --git a/utils/performanceTimer.go b/utils/performanceTimer.go
index 78dd09b20a..a872ab27ca 100644
--- a/utils/performanceTimer.go
+++ b/utils/performanceTimer.go
@@ -2,9 +2,12 @@ package utils
import (
"sort"
+ "sync"
"time"
)
+var l = sync.Mutex{}
+
// The "start" timestamp of a timing event.
var _pointsInTime = make(map[string]time.Time)
@@ -13,10 +16,12 @@ var _durationStorage = make(map[string][]float64)
// StartPerformanceMonitor will keep track of the start time of this event.
func StartPerformanceMonitor(key string) {
+ l.Lock()
if len(_durationStorage[key]) > 20 {
_durationStorage[key] = removeHighValue(_durationStorage[key])
}
_pointsInTime[key] = time.Now()
+ l.Unlock()
}
// GetAveragePerformance will return the average durations for the event.
@@ -26,12 +31,15 @@ func GetAveragePerformance(key string) float64 {
return 0
}
+ l.Lock()
delta := time.Since(timestamp).Seconds()
_durationStorage[key] = append(_durationStorage[key], delta)
if len(_durationStorage[key]) < 8 {
return 0
}
_durationStorage[key] = removeHighValue(_durationStorage[key])
+ l.Unlock()
+
return avg(_durationStorage[key])
}