️ refactor: 将排序的服务器列表的锁拆分出来

This commit is contained in:
naiba
2021-01-17 22:18:36 +08:00
parent d059835877
commit bf71aeaaf9
5 changed files with 24 additions and 17 deletions

View File

@@ -90,8 +90,8 @@ func (p *commonPage) service(c *gin.Context) {
}
func (cp *commonPage) home(c *gin.Context) {
dao.ServerLock.RLock()
defer dao.ServerLock.RUnlock()
dao.SortedServerLock.RLock()
defer dao.SortedServerLock.RUnlock()
c.HTML(http.StatusOK, "theme-"+dao.Conf.Site.Theme+"/home", mygin.CommonEnvironment(c, gin.H{
"Servers": dao.SortedServerList,
@@ -115,9 +115,9 @@ func (cp *commonPage) ws(c *gin.Context) {
}
defer conn.Close()
for {
dao.ServerLock.RLock()
dao.SortedServerLock.RLock()
err = conn.WriteJSON(dao.SortedServerList)
dao.ServerLock.RUnlock()
dao.SortedServerLock.RUnlock()
if err != nil {
break
}