3
0
mirror of https://github.com/ergochat/ergo.git synced 2024-11-14 07:59:31 +01:00

modes: Fix some more mutexes

This commit is contained in:
Daniel Oaks 2017-01-11 12:26:58 +10:00
parent c39bebc696
commit e9324c3250
2 changed files with 8 additions and 9 deletions

View File

@ -185,10 +185,10 @@ func (channel *Channel) Nick() string {
} }
// <mode> <mode params> // <mode> <mode params>
func (channel *Channel) ModeString(client *Client) (str string) { func (channel *Channel) modeStringNoLock(client *Client) (str string) {
channel.membersMutex.RLock() // RLock()
isMember := client.flags[Operator] || channel.members.Has(client) isMember := client.flags[Operator] || channel.members.Has(client)
channel.membersMutex.RUnlock() // RUnlock()
showKey := isMember && (channel.key != "") showKey := isMember && (channel.key != "")
showUserLimit := channel.userLimit > 0 showUserLimit := channel.userLimit > 0
@ -436,10 +436,9 @@ func (channel *Channel) applyModeFlag(client *Client, mode ChannelMode,
return false return false
} }
func (channel *Channel) applyModeMember(client *Client, mode ChannelMode, func (channel *Channel) applyModeMemberNoMutex(client *Client, mode ChannelMode,
op ModeOp, nick string) *ChannelModeChange { op ModeOp, nick string) *ChannelModeChange {
channel.membersMutex.Lock() // requires Lock()
defer channel.membersMutex.Unlock()
if nick == "" { if nick == "" {
//TODO(dan): shouldn't this be handled before it reaches this function? //TODO(dan): shouldn't this be handled before it reaches this function?

View File

@ -414,7 +414,7 @@ func cmodeHandler(server *Server, client *Client, msg ircmsg.IrcMessage) bool {
// so we only output one warning for each list type when full // so we only output one warning for each list type when full
listFullWarned := make(map[ChannelMode]bool) listFullWarned := make(map[ChannelMode]bool)
clientIsOp := channel.ClientIsAtLeast(client, ChannelOperator) clientIsOp := channel.clientIsAtLeastNoMutex(client, ChannelOperator)
var alreadySentPrivError bool var alreadySentPrivError bool
for _, change := range changes { for _, change := range changes {
@ -545,7 +545,7 @@ func cmodeHandler(server *Server, client *Client, msg ircmsg.IrcMessage) bool {
} }
} }
change := channel.applyModeMember(client, change.mode, change.op, change.arg) change := channel.applyModeMemberNoMutex(client, change.mode, change.op, change.arg)
if change != nil { if change != nil {
applied = append(applied, change) applied = append(applied, change)
} }
@ -561,7 +561,7 @@ func cmodeHandler(server *Server, client *Client, msg ircmsg.IrcMessage) bool {
} }
} else { } else {
//TODO(dan): we should just make ModeString return a slice here //TODO(dan): we should just make ModeString return a slice here
args := append([]string{client.nick, channel.name}, strings.Split(channel.ModeString(client), " ")...) args := append([]string{client.nick, channel.name}, strings.Split(channel.modeStringNoLock(client), " ")...)
client.Send(nil, client.nickMaskString, RPL_CHANNELMODEIS, args...) client.Send(nil, client.nickMaskString, RPL_CHANNELMODEIS, args...)
client.Send(nil, client.nickMaskString, RPL_CHANNELCREATED, client.nick, channel.name, strconv.FormatInt(channel.createdTime.Unix(), 10)) client.Send(nil, client.nickMaskString, RPL_CHANNELCREATED, client.nick, channel.name, strconv.FormatInt(channel.createdTime.Unix(), 10))
} }