🎨 Improve kernel stability by eliminating some data races https://github.com/siyuan-note/siyuan/issues/9842

This commit is contained in:
Daniel 2023-12-10 21:42:53 +08:00
parent 6addb73607
commit 8715578bca
No known key found for this signature in database
GPG key ID: 86211BA83DF03017

View file

@ -26,7 +26,6 @@ import (
"runtime/debug" "runtime/debug"
"sort" "sort"
"strings" "strings"
"sync"
"time" "time"
"github.com/88250/gulu" "github.com/88250/gulu"
@ -61,12 +60,9 @@ type Box struct {
historyGenerated int64 // 最近一次历史生成时间 historyGenerated int64 // 最近一次历史生成时间
} }
var statLock = sync.Mutex{}
func StatJob() { func StatJob() {
statLock.Lock()
defer statLock.Unlock()
Conf.m.Lock()
Conf.Stat.TreeCount = treenode.CountTrees() Conf.Stat.TreeCount = treenode.CountTrees()
Conf.Stat.CTreeCount = treenode.CeilTreeCount(Conf.Stat.TreeCount) Conf.Stat.CTreeCount = treenode.CeilTreeCount(Conf.Stat.TreeCount)
Conf.Stat.BlockCount = treenode.CountBlocks() Conf.Stat.BlockCount = treenode.CountBlocks()
@ -74,6 +70,7 @@ func StatJob() {
Conf.Stat.DataSize, Conf.Stat.AssetsSize = util.DataSize() Conf.Stat.DataSize, Conf.Stat.AssetsSize = util.DataSize()
Conf.Stat.CDataSize = util.CeilSize(Conf.Stat.DataSize) Conf.Stat.CDataSize = util.CeilSize(Conf.Stat.DataSize)
Conf.Stat.CAssetsSize = util.CeilSize(Conf.Stat.AssetsSize) Conf.Stat.CAssetsSize = util.CeilSize(Conf.Stat.AssetsSize)
Conf.m.Unlock()
Conf.Save() Conf.Save()
logging.LogInfof("auto stat [trees=%d, blocks=%d, dataSize=%s, assetsSize=%s]", Conf.Stat.TreeCount, Conf.Stat.BlockCount, humanize.Bytes(uint64(Conf.Stat.DataSize)), humanize.Bytes(uint64(Conf.Stat.AssetsSize))) logging.LogInfof("auto stat [trees=%d, blocks=%d, dataSize=%s, assetsSize=%s]", Conf.Stat.TreeCount, Conf.Stat.BlockCount, humanize.Bytes(uint64(Conf.Stat.DataSize)), humanize.Bytes(uint64(Conf.Stat.AssetsSize)))