3
0
mirror of https://github.com/ergochat/ergo.git synced 2024-11-11 06:29:29 +01:00

eliminate destroyMutex

This commit is contained in:
Shivaram Lingamneni 2017-10-11 12:48:06 -04:00
parent 545e8d71db
commit b86fc105cd

View File

@ -53,7 +53,6 @@ type Client struct {
channels ChannelSet channels ChannelSet
class *OperClass class *OperClass
ctime time.Time ctime time.Time
destroyMutex sync.Mutex
exitedSnomaskSent bool exitedSnomaskSent bool
flags map[Mode]bool flags map[Mode]bool
hasQuit bool hasQuit bool
@ -527,9 +526,12 @@ func (client *Client) Quit(message string) {
// destroy gets rid of a client, removes them from server lists etc. // destroy gets rid of a client, removes them from server lists etc.
func (client *Client) destroy() { func (client *Client) destroy() {
client.destroyMutex.Lock() // allow destroy() to execute at most once
defer client.destroyMutex.Unlock() client.stateMutex.Lock()
if client.isDestroyed { isDestroyed := client.isDestroyed
client.isDestroyed = true
client.stateMutex.Unlock()
if isDestroyed {
return return
} }
@ -538,7 +540,6 @@ func (client *Client) destroy() {
// send quit/error message to client if they haven't been sent already // send quit/error message to client if they haven't been sent already
client.Quit("Connection closed") client.Quit("Connection closed")
client.isDestroyed = true
client.server.whoWas.Append(client) client.server.whoWas.Append(client)
friends := client.Friends() friends := client.Friends()
friends.Remove(client) friends.Remove(client)