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

This commit is contained in:
Daniel 2023-12-08 13:05:50 +08:00
parent 8c5c62670e
commit bea32e96d5
No known key found for this signature in database
GPG key ID: 86211BA83DF03017
17 changed files with 158 additions and 117 deletions

View file

@ -28,6 +28,7 @@ import (
"strconv"
"strings"
"sync"
"sync/atomic"
"time"
"github.com/88250/gulu"
@ -60,9 +61,9 @@ func initEnvVars() {
}
var (
bootProgress float64 // 启动进度,从 0 到 100
bootDetails string // 启动细节描述
HttpServing = false // 是否 HTTP 伺服已经可用
bootProgress = atomic.Int32{} // 启动进度,从 0 到 100
bootDetails string // 启动细节描述
HttpServing = false // 是否 HTTP 伺服已经可用
)
func Boot() {
@ -146,40 +147,44 @@ func Boot() {
logBootInfo()
}
var bootDetailsLock = sync.Mutex{}
func setBootDetails(details string) {
bootDetailsLock.Lock()
bootDetails = "v" + Ver + " " + details
bootDetailsLock.Unlock()
}
func SetBootDetails(details string) {
if 100 <= bootProgress {
if 100 <= bootProgress.Load() {
return
}
setBootDetails(details)
}
func IncBootProgress(progress float64, details string) {
if 100 <= bootProgress {
func IncBootProgress(progress int32, details string) {
if 100 <= bootProgress.Load() {
return
}
bootProgress += progress
bootProgress.Add(progress)
setBootDetails(details)
}
func IsBooted() bool {
return 100 <= bootProgress
return 100 <= bootProgress.Load()
}
func GetBootProgressDetails() (float64, string) {
return bootProgress, bootDetails
func GetBootProgressDetails() (int32, string) {
return bootProgress.Load(), bootDetails
}
func GetBootProgress() float64 {
return bootProgress
func GetBootProgress() int32 {
return bootProgress.Load()
}
func SetBooted() {
setBootDetails("Finishing boot...")
bootProgress = 100
bootProgress.Store(100)
logging.LogInfof("kernel booted")
}