mirror of
https://github.com/ergochat/ergo.git
synced 2024-11-26 05:49:25 +01:00
use mutexes more
This commit is contained in:
parent
81a0f19390
commit
74b8221db7
@ -59,7 +59,10 @@ func (channel *Channel) Destroy() {
|
||||
channel.destroyed = true
|
||||
channel.members = make(ClientSet)
|
||||
})
|
||||
|
||||
channel.server.withMutex(func() {
|
||||
channel.server.channels.Remove(channel)
|
||||
})
|
||||
}
|
||||
|
||||
func (channel *Channel) Command(command ChannelCommand) {
|
||||
@ -112,14 +115,14 @@ func (channel *Channel) receiveReplies(replies <-chan Reply) {
|
||||
if DEBUG_CHANNEL {
|
||||
log.Printf("%s ← %s %s", channel, reply.Source(), reply)
|
||||
}
|
||||
channel.mutex.Lock()
|
||||
channel.withMutex(func() {
|
||||
for client := range channel.members {
|
||||
if IsPrivMsg(reply) && (reply.Source() == Identifier(client)) {
|
||||
continue
|
||||
}
|
||||
client.Reply(reply)
|
||||
}
|
||||
channel.mutex.Unlock()
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -51,6 +51,12 @@ func NewServer(config *Config) *Server {
|
||||
return server
|
||||
}
|
||||
|
||||
func (server *Server) withMutex(f func()) {
|
||||
server.mutex.Lock()
|
||||
defer server.mutex.Unlock()
|
||||
f()
|
||||
}
|
||||
|
||||
func (server *Server) receiveCommands() {
|
||||
for command := range server.commands {
|
||||
if DEBUG_SERVER {
|
||||
@ -139,7 +145,9 @@ func (s *Server) GetOrMakeChannel(name string) *Channel {
|
||||
|
||||
if !ok {
|
||||
channel = NewChannel(s, name)
|
||||
s.withMutex(func() {
|
||||
s.channels[name] = channel
|
||||
})
|
||||
}
|
||||
|
||||
return channel
|
||||
@ -331,9 +339,9 @@ func (m *QuitCommand) HandleServer(server *Server) {
|
||||
iclients.Remove(client)
|
||||
|
||||
for channel := range client.channels {
|
||||
channel.mutex.Lock()
|
||||
channel.withMutex(func() {
|
||||
channel.members.Remove(client)
|
||||
channel.mutex.Unlock()
|
||||
})
|
||||
}
|
||||
|
||||
client.Reply(RplError(server, client))
|
||||
|
Loading…
Reference in New Issue
Block a user