eliminate destroyMutex

This commit is contained in:
Shivaram Lingamneni 2017-10-11 12:48:06 -04:00
parent 545e8d71db
commit b86fc105cd
1 changed files with 6 additions and 5 deletions

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)