From 120d61d1b64001f08699534fb67bd08c0abeb229 Mon Sep 17 00:00:00 2001 From: Steven Polley Date: Fri, 30 Jun 2023 19:59:51 -0600 Subject: [PATCH] use read locks wherever we can --- main.go | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/main.go b/main.go index 2d770b5..5e6a491 100644 --- a/main.go +++ b/main.go @@ -112,12 +112,12 @@ func updateROMCache() { } // skip already cached files - romCache.Lock() + romCache.RLock() if _, ok := romCache.Cached[v.Name()]; ok { - romCache.Unlock() + romCache.RUnlock() continue } - romCache.Unlock() + romCache.RUnlock() wg.Add(1) go func(v fs.DirEntry) { @@ -188,9 +188,9 @@ func lineageOSROMListHandler(w http.ResponseWriter, r *http.Request) { } }() - romCache.Lock() + romCache.RLock() httpResponseJSON := &HTTPResponseJSON{Response: romCache.ROMs} - romCache.Unlock() + romCache.RUnlock() b, err := json.Marshal(httpResponseJSON) if err != nil {