From 1b8d3472a077dbb4e74d34c8fd7243e5ebd72a94 Mon Sep 17 00:00:00 2001 From: aozhiwei Date: Sat, 25 May 2024 11:58:31 +0800 Subject: [PATCH] 1 --- server/statserver/session/sessionmgr.go | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/server/statserver/session/sessionmgr.go b/server/statserver/session/sessionmgr.go index bc66622b..712a37d0 100644 --- a/server/statserver/session/sessionmgr.go +++ b/server/statserver/session/sessionmgr.go @@ -11,6 +11,7 @@ type userSession struct { accountId string sessionId string lastUpdateTime int64 + timerWp *q5.XTimerWp } type sessionMgr struct { @@ -40,20 +41,23 @@ func (this *sessionMgr) UpdateSession(accountId string, sessionId string) { session.lastUpdateTime = f5.GetApp().GetRealSeconds() return } + defer this.lock.Unlock() this.lock.Lock() session = this.getSession(accountId) if session != nil { session.lastUpdateTime = f5.GetApp().GetRealSeconds() - this.lock.Unlock() - return - } + } else { + session = new(userSession) + session.accountId = accountId + session.sessionId = sessionId + session.lastUpdateTime = f5.GetApp().GetRealSeconds() + this.idHash.Store(accountId, session) + session.timerWp = this.timer.SetIntervalWp( + 1, + func (e int32, args *q5.Args) { - session = new(userSession) - session.accountId = accountId - session.sessionId = sessionId - session.lastUpdateTime = f5.GetApp().GetRealSeconds() - this.idHash.Store(accountId, session) - this.lock.Unlock() + }) + } } func (this *sessionMgr) getSession(accountId string) *userSession {