3
0
mirror of https://github.com/ergochat/ergo.git synced 2024-11-10 22:19:31 +01:00

Prevent copying locks because that's silly

This commit is contained in:
Daniel Oaks 2017-04-30 11:12:25 +10:00
parent 4254672133
commit 2bd4d03ecc
3 changed files with 20 additions and 27 deletions

View File

@ -15,7 +15,7 @@ func (client *Client) alertMonitors() {
// alert monitors // alert monitors
for _, mClient := range client.server.monitoring[client.nickCasefolded] { for _, mClient := range client.server.monitoring[client.nickCasefolded] {
// don't have to notify ourselves // don't have to notify ourselves
if &mClient != client { if mClient != client {
mClient.SendFromClient("", client, nil, RPL_MONONLINE, mClient.nick, client.nickMaskString) mClient.SendFromClient("", client, nil, RPL_MONONLINE, mClient.nick, client.nickMaskString)
} }
} }
@ -28,7 +28,7 @@ func (client *Client) clearMonitorList() {
orig := client.server.monitoring[name] orig := client.server.monitoring[name]
var index int var index int
for i, cli := range orig { for i, cli := range orig {
if &cli == client { if cli == client {
index = i index = i
break break
} }
@ -87,7 +87,7 @@ func monitorRemoveHandler(server *Server, client *Client, msg ircmsg.IrcMessage)
orig := server.monitoring[casefoldedTarget] orig := server.monitoring[casefoldedTarget]
var index int var index int
for i, cli := range orig { for i, cli := range orig {
if &cli == client { if cli == client {
index = i index = i
break break
} }
@ -139,7 +139,7 @@ func monitorAddHandler(server *Server, client *Client, msg ircmsg.IrcMessage) bo
client.monitoring[casefoldedTarget] = true client.monitoring[casefoldedTarget] = true
orig := server.monitoring[casefoldedTarget] orig := server.monitoring[casefoldedTarget]
server.monitoring[casefoldedTarget] = append(orig, *client) server.monitoring[casefoldedTarget] = append(orig, client)
} }
// add to online / offline lists // add to online / offline lists

View File

@ -107,7 +107,7 @@ type Server struct {
listenerUpdateMutex sync.Mutex listenerUpdateMutex sync.Mutex
logger *logger.Manager logger *logger.Manager
MaxSendQBytes uint64 MaxSendQBytes uint64
monitoring map[string][]Client monitoring map[string][]*Client
motdLines []string motdLines []string
name string name string
nameCasefolded string nameCasefolded string
@ -193,7 +193,7 @@ func NewServer(configFilename string, config *Config, logger *logger.Manager) (*
accountAuthenticationEnabled: config.Accounts.AuthenticationEnabled, accountAuthenticationEnabled: config.Accounts.AuthenticationEnabled,
accounts: make(map[string]*ClientAccount), accounts: make(map[string]*ClientAccount),
channelRegistrationEnabled: config.Channels.Registration.Enabled, channelRegistrationEnabled: config.Channels.Registration.Enabled,
channels: NewChannelNameMap(), channels: *NewChannelNameMap(),
checkIdent: config.Server.CheckIdent, checkIdent: config.Server.CheckIdent,
clients: NewClientLookupSet(), clients: NewClientLookupSet(),
commands: make(chan Command), commands: make(chan Command),
@ -219,7 +219,7 @@ func NewServer(configFilename string, config *Config, logger *logger.Manager) (*
listeners: make(map[string]ListenerInterface), listeners: make(map[string]ListenerInterface),
logger: logger, logger: logger,
MaxSendQBytes: config.Server.MaxSendQBytes, MaxSendQBytes: config.Server.MaxSendQBytes,
monitoring: make(map[string][]Client), monitoring: make(map[string][]*Client),
name: config.Server.Name, name: config.Server.Name,
nameCasefolded: casefoldedName, nameCasefolded: casefoldedName,
networkName: config.Network.Name, networkName: config.Network.Name,

View File

@ -11,22 +11,21 @@ import (
"sync" "sync"
) )
// // ChannelNameMap is a map that converts channel names to actual channel objects.
// simple types
//
type ChannelNameMap struct { type ChannelNameMap struct {
ChansLock sync.RWMutex ChansLock sync.RWMutex
Chans map[string]*Channel Chans map[string]*Channel
} }
func NewChannelNameMap() ChannelNameMap { // NewChannelNameMap returns a new ChannelNameMap.
func NewChannelNameMap() *ChannelNameMap {
var channels ChannelNameMap var channels ChannelNameMap
channels.Chans = make(map[string]*Channel) channels.Chans = make(map[string]*Channel)
return channels return &channels
} }
func (channels ChannelNameMap) Get(name string) *Channel { // Get returns the given channel if it exists.
func (channels *ChannelNameMap) Get(name string) *Channel {
name, err := CasefoldChannel(name) name, err := CasefoldChannel(name)
if err == nil { if err == nil {
channels.ChansLock.RLock() channels.ChansLock.RLock()
@ -36,7 +35,8 @@ func (channels ChannelNameMap) Get(name string) *Channel {
return nil return nil
} }
func (channels ChannelNameMap) Add(channel *Channel) error { // Add adds the given channel to our map.
func (channels *ChannelNameMap) Add(channel *Channel) error {
channels.ChansLock.Lock() channels.ChansLock.Lock()
defer channels.ChansLock.Unlock() defer channels.ChansLock.Unlock()
if channels.Chans[channel.nameCasefolded] != nil { if channels.Chans[channel.nameCasefolded] != nil {
@ -46,7 +46,8 @@ func (channels ChannelNameMap) Add(channel *Channel) error {
return nil return nil
} }
func (channels ChannelNameMap) Remove(channel *Channel) error { // Remove removes the given channel from our map.
func (channels *ChannelNameMap) Remove(channel *Channel) error {
channels.ChansLock.Lock() channels.ChansLock.Lock()
defer channels.ChansLock.Unlock() defer channels.ChansLock.Unlock()
if channel != channels.Chans[channel.nameCasefolded] { if channel != channels.Chans[channel.nameCasefolded] {
@ -56,7 +57,8 @@ func (channels ChannelNameMap) Remove(channel *Channel) error {
return nil return nil
} }
func (channels ChannelNameMap) Len() int { // Len returns how many channels we have.
func (channels *ChannelNameMap) Len() int {
channels.ChansLock.RLock() channels.ChansLock.RLock()
defer channels.ChansLock.RUnlock() defer channels.ChansLock.RUnlock()
return len(channels.Chans) return len(channels.Chans)
@ -72,7 +74,7 @@ func (set ModeSet) String() string {
index := 0 index := 0
for mode := range set { for mode := range set {
strs[index] = mode.String() strs[index] = mode.String()
index += 1 index++
} }
return strings.Join(strs, "") return strings.Join(strs, "")
} }
@ -139,12 +141,3 @@ func (channels ChannelSet) First() *Channel {
} }
return nil return nil
} }
//
// interfaces
//
type Identifiable interface {
Id() string
Nick() string
}