3
0
mirror of https://github.com/ergochat/ergo.git synced 2024-12-23 03:02:48 +01:00

eliminate quitMutex

This commit is contained in:
Shivaram Lingamneni 2017-10-10 20:49:29 -04:00
parent b0649cb5d3
commit 545e8d71db

View File

@ -70,7 +70,6 @@ type Client struct {
proxiedIP string // actual remote IP if using the PROXY protocol proxiedIP string // actual remote IP if using the PROXY protocol
quitMessage string quitMessage string
quitMessageSent bool quitMessageSent bool
quitMutex sync.Mutex
quitTimer *time.Timer quitTimer *time.Timer
rawHostname string rawHostname string
realname string realname string
@ -505,19 +504,25 @@ func (client *Client) RplISupport() {
// Quit sends the given quit message to the client (but does not destroy them). // Quit sends the given quit message to the client (but does not destroy them).
func (client *Client) Quit(message string) { func (client *Client) Quit(message string) {
client.quitMutex.Lock() client.stateMutex.Lock()
defer client.quitMutex.Unlock() alreadyQuit := client.quitMessageSent
if !client.quitMessageSent { if !alreadyQuit {
quitMsg := ircmsg.MakeMessage(nil, client.nickMaskString, "QUIT", message)
quitLine, _ := quitMsg.Line()
errorMsg := ircmsg.MakeMessage(nil, "", "ERROR", message)
errorLine, _ := errorMsg.Line()
client.socket.SetFinalData(quitLine + errorLine)
client.quitMessageSent = true client.quitMessageSent = true
client.quitMessage = message client.quitMessage = message
} }
client.stateMutex.Unlock()
if alreadyQuit {
return
}
quitMsg := ircmsg.MakeMessage(nil, client.nickMaskString, "QUIT", message)
quitLine, _ := quitMsg.Line()
errorMsg := ircmsg.MakeMessage(nil, "", "ERROR", message)
errorLine, _ := errorMsg.Line()
client.socket.SetFinalData(quitLine + errorLine)
} }
// destroy gets rid of a client, removes them from server lists etc. // destroy gets rid of a client, removes them from server lists etc.