mirror of
https://github.com/siyuan-note/siyuan.git
synced 2025-05-17 09:30:48 +08:00
🎨 Improve kernel stability by eliminating some data races https://github.com/siyuan-note/siyuan/issues/9842
This commit is contained in:
parent
dbd52231e9
commit
071f3f9af8
@ -44,7 +44,7 @@ func autoOCRAssets() {
|
|||||||
util.AssetsTexts[p] = text
|
util.AssetsTexts[p] = text
|
||||||
util.AssetsTextsLock.Unlock()
|
util.AssetsTextsLock.Unlock()
|
||||||
if "" != text {
|
if "" != text {
|
||||||
util.AssetsTextsChanged = true
|
util.AssetsTextsChanged.Store(true)
|
||||||
}
|
}
|
||||||
if 7 <= i { // 一次任务中最多处理 7 张图片,防止长时间占用系统资源
|
if 7 <= i { // 一次任务中最多处理 7 张图片,防止长时间占用系统资源
|
||||||
break
|
break
|
||||||
@ -71,7 +71,7 @@ func cleanNotExistAssetsTexts() {
|
|||||||
|
|
||||||
for _, asset := range toRemoves {
|
for _, asset := range toRemoves {
|
||||||
delete(util.AssetsTexts, asset)
|
delete(util.AssetsTexts, asset)
|
||||||
util.AssetsTextsChanged = true
|
util.AssetsTextsChanged.Store(true)
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@ -134,7 +134,7 @@ func LoadAssetsTexts() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func SaveAssetsTexts() {
|
func SaveAssetsTexts() {
|
||||||
if !util.AssetsTextsChanged {
|
if !util.AssetsTextsChanged.Load() {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -160,5 +160,5 @@ func SaveAssetsTexts() {
|
|||||||
logging.LogWarnf("save assets texts [size=%s] to [%s], elapsed [%.2fs]", humanize.Bytes(uint64(len(data))), assetsTextsPath, elapsed)
|
logging.LogWarnf("save assets texts [size=%s] to [%s], elapsed [%.2fs]", humanize.Bytes(uint64(len(data))), assetsTextsPath, elapsed)
|
||||||
}
|
}
|
||||||
|
|
||||||
util.AssetsTextsChanged = false
|
util.AssetsTextsChanged.Store(false)
|
||||||
}
|
}
|
||||||
|
@ -41,7 +41,7 @@ var (
|
|||||||
TesseractMaxSize = 2 * 1000 * uint64(1000)
|
TesseractMaxSize = 2 * 1000 * uint64(1000)
|
||||||
AssetsTexts = map[string]string{}
|
AssetsTexts = map[string]string{}
|
||||||
AssetsTextsLock = sync.Mutex{}
|
AssetsTextsLock = sync.Mutex{}
|
||||||
AssetsTextsChanged = false
|
AssetsTextsChanged = atomic.Bool{}
|
||||||
|
|
||||||
TesseractLangs []string
|
TesseractLangs []string
|
||||||
)
|
)
|
||||||
@ -50,7 +50,7 @@ func SetAssetText(asset, text string) {
|
|||||||
AssetsTextsLock.Lock()
|
AssetsTextsLock.Lock()
|
||||||
AssetsTexts[asset] = text
|
AssetsTexts[asset] = text
|
||||||
AssetsTextsLock.Unlock()
|
AssetsTextsLock.Unlock()
|
||||||
AssetsTextsChanged = true
|
AssetsTextsChanged.Store(true)
|
||||||
}
|
}
|
||||||
|
|
||||||
func ExistsAssetText(asset string) (ret bool) {
|
func ExistsAssetText(asset string) (ret bool) {
|
||||||
@ -76,7 +76,7 @@ func GetAssetText(asset string, force bool) (ret string) {
|
|||||||
AssetsTexts[asset] = ret
|
AssetsTexts[asset] = ret
|
||||||
AssetsTextsLock.Unlock()
|
AssetsTextsLock.Unlock()
|
||||||
if "" != ret {
|
if "" != ret {
|
||||||
AssetsTextsChanged = true
|
AssetsTextsChanged.Store(true)
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user