summaryrefslogtreecommitdiff
diff options
authorPhilip Meulengracht <philip.meulengracht@canonical.com>2023-07-07 12:53:16 +0200
committerPhilip Meulengracht <the_meulengracht@hotmail.com>2023-07-10 14:20:50 +0200
commit5379e2c609795cb334f2a58a835f0801f69e14b6 (patch)
tree9c48d926444aa9dfe8bd1151e7ec3a6a344bebf5
parentd4b64e97a7c59a55616f22a75366a4e024f7b022 (diff)
o/state: clarify why we are s.reading()
As we are not changing state that goes to disk, but we want serialized access we use s.reading() and not s.writing()
-rw-r--r--overlord/state/state.go4
1 files changed, 4 insertions, 0 deletions
diff --git a/overlord/state/state.go b/overlord/state/state.go
index 60cd3ef60e..62f7910c40 100644
--- a/overlord/state/state.go
+++ b/overlord/state/state.go
@@ -498,6 +498,8 @@ func (s *State) GetMaybeTimings(timings interface{}) error {
// as quickly as possible, and should avoid the use of i/o code or blocking, as this
// will stop the entire task system.
func (s *State) AddTaskStatusChangedHandler(f func(t *Task, old, new Status)) (id int) {
+ // We are reading here as we want to ensure access to the state is serialized,
+ // and not writing as we are not changing the part of state that goes on the disk.
s.reading()
id = s.lastHandlerId
s.lastHandlerId++
@@ -524,6 +526,8 @@ func (s *State) notifyTaskStatusChangedHandlers(t *Task, old, new Status) {
// as quickly as possible, and should avoid the use of i/o code or blocking, as this
// will stop the entire task system.
func (s *State) AddChangeStatusChangedHandler(f func(chg *Change, old, new Status)) (id int) {
+ // We are reading here as we want to ensure access to the state is serialized,
+ // and not writing as we are not changing the part of state that goes on the disk.
s.reading()
id = s.lastHandlerId
s.lastHandlerId++