Browse Source

remove utils.ConfigStore in favor of atomic.Pointer[T]

tags/v2.11.0-rc1
Shivaram Lingamneni 1 year ago
parent
commit
a99c8a42f9
3 changed files with 4 additions and 36 deletions
  1. 1
    1
      irc/getters.go
  2. 3
    2
      irc/server.go
  3. 0
    33
      irc/utils/config.go

+ 1
- 1
irc/getters.go View File

@@ -16,7 +16,7 @@ import (
16 16
 )
17 17
 
18 18
 func (server *Server) Config() (config *Config) {
19
-	return server.config.Get()
19
+	return server.config.Load()
20 20
 }
21 21
 
22 22
 func (server *Server) ChannelRegistrationEnabled() bool {

+ 3
- 2
irc/server.go View File

@@ -15,6 +15,7 @@ import (
15 15
 	"strconv"
16 16
 	"strings"
17 17
 	"sync"
18
+	"sync/atomic"
18 19
 	"syscall"
19 20
 	"time"
20 21
 
@@ -66,7 +67,7 @@ type Server struct {
66 67
 	channels          ChannelManager
67 68
 	channelRegistry   ChannelRegistry
68 69
 	clients           ClientManager
69
-	config            utils.ConfigStore[Config]
70
+	config            atomic.Pointer[Config]
70 71
 	configFilename    string
71 72
 	connectionLimiter connection_limits.Limiter
72 73
 	ctime             time.Time
@@ -707,7 +708,7 @@ func (server *Server) applyConfig(config *Config) (err error) {
707 708
 	config.Server.Cloaks.SetSecret(LoadCloakSecret(server.store))
708 709
 
709 710
 	// activate the new config
710
-	server.config.Set(config)
711
+	server.config.Store(config)
711 712
 
712 713
 	// load [dk]-lines, registered users and channels, etc.
713 714
 	if initial {

+ 0
- 33
irc/utils/config.go View File

@@ -1,33 +0,0 @@
1
-// Copyright (c) 2022 Shivaram Lingamneni
2
-// released under the MIT license
3
-
4
-package utils
5
-
6
-import (
7
-	"sync/atomic"
8
-	"unsafe"
9
-)
10
-
11
-/*
12
-This can be used to implement the following pattern:
13
-
14
-1. Prepare a config object (this can be arbitrarily expensive)
15
-2. Take a pointer to the config object and use Set() to install it
16
-3. Use Get() to access the config from any goroutine
17
-4. To update the config, call Set() again with a new prepared config object
18
-5. As long as any individual config object is not modified (by any goroutine)
19
-   after it is installed with Set(), this is free of data races, and Get()
20
-   is extremely cheap (on amd64 it compiles down to plain MOV instructions).
21
-*/
22
-
23
-type ConfigStore[Config any] struct {
24
-	ptr unsafe.Pointer
25
-}
26
-
27
-func (c *ConfigStore[Config]) Get() *Config {
28
-	return (*Config)(atomic.LoadPointer(&c.ptr))
29
-}
30
-
31
-func (c *ConfigStore[Config]) Set(ptr *Config) {
32
-	atomic.StorePointer(&c.ptr, unsafe.Pointer(ptr))
33
-}

Loading…
Cancel
Save