From 7040f1c8d0b25d0b503ecf8ba76439cf19ed4f58 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ken-H=C3=A5vard=20Lieng?= Date: Tue, 16 Jun 2020 01:29:35 +0200 Subject: [PATCH] Use mutex pointer in network state --- storage/network.go | 7 +++++-- storage/user.go | 1 + 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/storage/network.go b/storage/network.go index 5266423a..af2d336b 100644 --- a/storage/network.go +++ b/storage/network.go @@ -27,7 +27,7 @@ type Network struct { user *User client *irc.Client channels map[string]*Channel - lock sync.Mutex + lock *sync.Mutex } func (n *Network) Save() error { @@ -53,6 +53,7 @@ func (n *Network) Copy() *Network { user: n.user, client: n.client, channels: n.channels, + lock: &sync.Mutex{}, } n.lock.Unlock() @@ -137,6 +138,7 @@ func (n *Network) NewChannel(name string) *Channel { Network: n.Host, Name: name, user: n.user, + lock: &sync.Mutex{}, } } @@ -162,7 +164,7 @@ type Channel struct { Joined bool user *User - lock sync.Mutex + lock *sync.Mutex } func (c *Channel) Save() error { @@ -177,6 +179,7 @@ func (c *Channel) Copy() *Channel { Topic: c.Topic, Joined: c.Joined, user: c.user, + lock: &sync.Mutex{}, } c.lock.Unlock() diff --git a/storage/user.go b/storage/user.go index 8a6a7bf0..3ce2e5ce 100644 --- a/storage/user.go +++ b/storage/user.go @@ -167,6 +167,7 @@ func (u *User) NewNetwork(template *Network, client *irc.Client) *Network { template.user = u template.client = client template.channels = map[string]*Channel{} + template.lock = &sync.Mutex{} return template }