mirror of
https://github.com/siyuan-note/siyuan.git
synced 2025-12-16 22:50:13 +01:00
🎨 Improve kernel stability by eliminating some data races https://github.com/siyuan-note/siyuan/issues/9842
This commit is contained in:
parent
8c5c62670e
commit
bea32e96d5
17 changed files with 158 additions and 117 deletions
|
|
@ -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")
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue