mirror of
https://github.com/ergochat/ergo.git
synced 2024-11-25 21:39:25 +01:00
fix another race
This commit is contained in:
parent
ae02596214
commit
213afc0481
@ -186,16 +186,22 @@ func (channel *Channel) ModeString() (str string) {
|
||||
return
|
||||
}
|
||||
|
||||
func (channel *Channel) Join(client *Client) {
|
||||
func (channel *Channel) withMutex(f func()) {
|
||||
channel.mutex.Lock()
|
||||
channel.members.Add(client)
|
||||
if len(channel.members) == 1 {
|
||||
channel.members[client][ChannelCreator] = true
|
||||
channel.members[client][ChannelOperator] = true
|
||||
}
|
||||
channel.mutex.Unlock()
|
||||
defer channel.mutex.Unlock()
|
||||
f()
|
||||
}
|
||||
|
||||
func (channel *Channel) Join(client *Client) {
|
||||
channel.withMutex(func() {
|
||||
channel.members.Add(client)
|
||||
if len(channel.members) == 1 {
|
||||
channel.members[client][ChannelCreator] = true
|
||||
channel.members[client][ChannelOperator] = true
|
||||
}
|
||||
client.channels.Add(channel)
|
||||
})
|
||||
|
||||
client.channels.Add(channel)
|
||||
channel.Reply(RplJoin(client, channel))
|
||||
channel.GetTopic(client)
|
||||
channel.GetUsers(client)
|
||||
|
Loading…
Reference in New Issue
Block a user