From 69d30587cb124501cac5ff613465e27844305e7a Mon Sep 17 00:00:00 2001 From: BroodjeAap Date: Thu, 9 Jul 2020 19:03:38 +0000 Subject: [PATCH] added mutex to SaveStreamInstant to prevent weirdness --- stream.go | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/stream.go b/stream.go index 7332eea..6978c57 100755 --- a/stream.go +++ b/stream.go @@ -8,6 +8,7 @@ import ( "net/http" "os" "path/filepath" + "sync" "time" "gocv.io/x/gocv" @@ -18,6 +19,7 @@ type Stream struct { URL string `json:"url"` Base64 string `json:"base64"` Interval int `json:"interval"` + FileLock sync.Mutex } // NewStream creates a new Stream Object @@ -80,6 +82,7 @@ func (s Stream) GetStreamInstant() gocv.Mat { // SaveStreamInstant writes the img to the CurrentStreamInstantPath, moves existing instant to PreviousStreamInstantPath func (s Stream) SaveStreamInstant(mat gocv.Mat) { + s.FileLock.Lock() streamStoreDir := s.GetStreamStoreDirPath() os.MkdirAll(streamStoreDir, os.ModePerm) @@ -95,6 +98,7 @@ func (s Stream) SaveStreamInstant(mat gocv.Mat) { if swap { s.SwapInstants(s.GetPreviousInstantPath(), s.GetCurrentInstantPath(), s.GetNextInstantPath()) } + s.FileLock.Unlock() } // SwapInstants swaps the file location, first current -> previous and then next -> current