mirror of
https://github.com/superseriousbusiness/gotosocial.git
synced 2024-12-23 02:32:12 +00:00
[feature] Use Read/Write lock for config (#1969)
This commit is contained in:
parent
6de5ca46f8
commit
f0dad439f6
|
@ -105,9 +105,9 @@ func generateFields(output io.Writer, prefixes []string, t reflect.Type) {
|
||||||
// ConfigState structure helper methods
|
// ConfigState structure helper methods
|
||||||
fmt.Fprintf(output, "// Get%s safely fetches the Configuration value for state's '%s' field\n", name, fieldPath)
|
fmt.Fprintf(output, "// Get%s safely fetches the Configuration value for state's '%s' field\n", name, fieldPath)
|
||||||
fmt.Fprintf(output, "func (st *ConfigState) Get%s() (v %s) {\n", name, fieldType)
|
fmt.Fprintf(output, "func (st *ConfigState) Get%s() (v %s) {\n", name, fieldType)
|
||||||
fmt.Fprintf(output, "\tst.mutex.Lock()\n")
|
fmt.Fprintf(output, "\tst.mutex.RLock()\n")
|
||||||
fmt.Fprintf(output, "\tv = st.config.%s\n", fieldPath)
|
fmt.Fprintf(output, "\tv = st.config.%s\n", fieldPath)
|
||||||
fmt.Fprintf(output, "\tst.mutex.Unlock()\n")
|
fmt.Fprintf(output, "\tst.mutex.RUnlock()\n")
|
||||||
fmt.Fprintf(output, "\treturn\n")
|
fmt.Fprintf(output, "\treturn\n")
|
||||||
fmt.Fprintf(output, "}\n\n")
|
fmt.Fprintf(output, "}\n\n")
|
||||||
fmt.Fprintf(output, "// Set%s safely sets the Configuration value for state's '%s' field\n", name, fieldPath)
|
fmt.Fprintf(output, "// Set%s safely sets the Configuration value for state's '%s' field\n", name, fieldPath)
|
||||||
|
|
File diff suppressed because it is too large
Load diff
|
@ -32,7 +32,7 @@
|
||||||
type ConfigState struct { //nolint
|
type ConfigState struct { //nolint
|
||||||
viper *viper.Viper
|
viper *viper.Viper
|
||||||
config Configuration
|
config Configuration
|
||||||
mutex sync.Mutex
|
mutex sync.RWMutex
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewState returns a new initialized ConfigState instance.
|
// NewState returns a new initialized ConfigState instance.
|
||||||
|
|
Loading…
Reference in a new issue