resolve XXX question introduced by e42ebd8

This commit is contained in:
nytpu
2021-03-17 11:23:44 -06:00
parent 8426bb6494
commit 593c1288bc
+5 -33
View File
@@ -2,7 +2,7 @@
// SPDX-License-Identifier: AGPL-3.0-or-later // SPDX-License-Identifier: AGPL-3.0-or-later
// For more license details, see LICENSE or <https://www.gnu.org/licenses/agpl-3.0.html>. // For more license details, see LICENSE or <https://www.gnu.org/licenses/agpl-3.0.html>.
// This file incorporates code from makeworlds's amfora: // This file incorporates code from makeworld's amfora:
// https://github.com/makeworld-the-better-one/amfora/blob/master/subscriptions/structs.go // https://github.com/makeworld-the-better-one/amfora/blob/master/subscriptions/structs.go
// Original source is Copyright 2020 makeworld and is licensed under the // Original source is Copyright 2020 makeworld and is licensed under the
// terms of the GNU General Public License Version 3.0. // terms of the GNU General Public License Version 3.0.
@@ -20,14 +20,14 @@ import (
"github.com/mmcdole/gofeed" "github.com/mmcdole/gofeed"
) )
// jsonData is used for both reading from json and for storing the global feeds // FullData is used for both reading from json and for storing the global feeds
// map. contains read mutexes so concurrency can be used. // map. contains read mutexes so concurrency can be used.
type JsonData struct { type FullData struct {
Feeds map[url.URL]*Feed `json:"feeds,omitempty"` Feeds map[url.URL]*Feed `json:"feeds,omitempty"`
Pages map[url.URL]*Page `json:"pages,omitempty"` Pages map[url.URL]*Page `json:"pages,omitempty"`
feedsMu *sync.RWMutex FeedsMu *sync.RWMutex
pagesMu *sync.RWMutex PagesMu *sync.RWMutex
} }
// Feed holds all the necessary fields when storing a feed // Feed holds all the necessary fields when storing a feed
@@ -110,34 +110,6 @@ func (f *Feed) Swap(i, j int) {
f.Items[i], f.Items[j] = f.Items[j], f.Items[i] f.Items[i], f.Items[j] = f.Items[j], f.Items[i]
} }
// XXX: do both feedsMu and pagesMu need to be (un)locked together or can they
// be locked individually? they are in the same struct but they're different
// elements so they shuld be able to be accessed at the same time, right?
// Lock locks both feed and page mutexes.
func (j *JsonData) Lock() {
j.feedsMu.Lock()
j.pagesMu.Lock()
}
// Unlock unlocks both feed and page mutexes.
func (j *JsonData) Unlock() {
j.feedsMu.Unlock()
j.pagesMu.Unlock()
}
// RLock read-locks both feed and page mutexes.
func (j *JsonData) RLock() {
j.feedsMu.RLock()
j.pagesMu.RLock()
}
// RUnlock read-unlocks both feed and page mutexes.
func (j *JsonData) RUnlock() {
j.feedsMu.RUnlock()
j.pagesMu.RUnlock()
}
// PageEntry is a single item on a subscriptions page. It is used for both feeds // PageEntry is a single item on a subscriptions page. It is used for both feeds
// and pages. // and pages.
type PageEntry struct { type PageEntry struct {