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

synchronize accesses to client.atime

This commit is contained in:
Shivaram Lingamneni 2017-12-02 20:05:06 -05:00
parent ad351268be
commit f5e7ec525d

View File

@ -261,6 +261,8 @@ func (client *Client) run() {
// Active updates when the client was last 'active' (i.e. the user should be sitting in front of their client). // Active updates when the client was last 'active' (i.e. the user should be sitting in front of their client).
func (client *Client) Active() { func (client *Client) Active() {
client.stateMutex.Lock()
defer client.stateMutex.Unlock()
client.atime = time.Now() client.atime = time.Now()
} }
@ -298,6 +300,8 @@ func (client *Client) Register() {
// IdleTime returns how long this client's been idle. // IdleTime returns how long this client's been idle.
func (client *Client) IdleTime() time.Duration { func (client *Client) IdleTime() time.Duration {
client.stateMutex.RLock()
defer client.stateMutex.RUnlock()
return time.Since(client.atime) return time.Since(client.atime)
} }