Skip to content

Commit

Permalink
amend! Make common.UserConfig an atomic.Value for safe concurrent access
Browse files Browse the repository at this point in the history
Make common.UserConfig an atomic.Pointer for safe concurrent access

Currently, userConfig is only read once at startup and then never changes. Later
in this branch, we will add the possibility to reload the user config; this can
happen either when switching repositories, or when the user has edited the
config file. In both cases, reloading happens on the main thread, but the user
config could be accessed concurrently from background threads, so we need to
make this safe.
  • Loading branch information
stefanhaller committed Aug 4, 2024
1 parent 78d9daf commit a682b8d
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions pkg/common/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import (
type Common struct {
Log *logrus.Entry
Tr *i18n.TranslationSet
userConfig atomic.Value
userConfig atomic.Pointer[config.UserConfig]
AppState *config.AppState
Debug bool
// for interacting with the filesystem. We use afero rather than the default
Expand All @@ -22,7 +22,7 @@ type Common struct {
}

func (c *Common) UserConfig() *config.UserConfig {
return c.userConfig.Load().(*config.UserConfig)
return c.userConfig.Load()
}

func (c *Common) SetUserConfig(userConfig *config.UserConfig) {
Expand Down

0 comments on commit a682b8d

Please sign in to comment.