Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow disabling of the thread checks as a "migration" - a pattern we can re-use #5425

Merged
merged 9 commits into from
Jan 21, 2025
Prev Previous commit
Next Next commit
Revert "Fixup migration setting to be thread safe"
This reverts commit 6f07422.
andydotxyz committed Jan 17, 2025
commit 3e7e92d31d276092823691f09c6a987a18805aa8
9 changes: 0 additions & 9 deletions app/meta.go
Original file line number Diff line number Diff line change
@@ -2,7 +2,6 @@ package app

import (
"fyne.io/fyne/v2"
"fyne.io/fyne/v2/internal/build"
)

var meta = fyne.AppMetadata{
@@ -25,8 +24,6 @@ func SetMetadata(m fyne.AppMetadata) {
}
if meta.Migrations == nil {
meta.Migrations = map[string]bool{}
} else {
setupMigrations(m.Migrations)
}
}

@@ -37,9 +34,3 @@ func (a *fyneApp) Metadata() fyne.AppMetadata {

return meta
}

func setupMigrations(data map[string]bool) {
if done, ok := data["fyneDo"]; ok && done {
build.DisableThreadChecks = true
}
}
1 change: 0 additions & 1 deletion app/meta_development.go
Original file line number Diff line number Diff line change
@@ -44,7 +44,6 @@ func checkLocalMetadata() {
meta.Release = false
meta.Custom = data.Development
meta.Migrations = data.Migrations
setupMigrations(data.Migrations)
}

func getProjectPath() string {
4 changes: 2 additions & 2 deletions internal/async/goroutine.go
Original file line number Diff line number Diff line change
@@ -30,7 +30,7 @@ func IsMainGoroutine() bool {
//
// This will be removed later and should never be public
func EnsureNotMain(fn func()) {
if build.DisableThreadChecks || !build.HasHints || !IsMainGoroutine() {
if build.MigratedToFyneDo() || !build.HasHints || !IsMainGoroutine() {
fn()
return
}
@@ -47,7 +47,7 @@ func EnsureNotMain(fn func()) {
//
// This will be removed later and should never be public
func EnsureMain(fn func()) {
if build.DisableThreadChecks || !build.HasHints || IsMainGoroutine() {
if build.MigratedToFyneDo() || !build.HasHints || IsMainGoroutine() {
fn()
return
}
14 changes: 14 additions & 0 deletions internal/build/build.go
Original file line number Diff line number Diff line change
@@ -1,2 +1,16 @@
// Package build contains information about they type of build currently running.
package build

import "fyne.io/fyne/v2"

func MigratedToFyneDo() bool {
if DisableThreadChecks {
return true
}

v, ok := fyne.CurrentApp().Metadata().Migrations["fyneDo"]
if ok {
return v
}
return false
}
2 changes: 1 addition & 1 deletion internal/build/migrated_fynedo.go
Original file line number Diff line number Diff line change
@@ -3,4 +3,4 @@
package build

// DisableThreadChecks disables the thread safety checks for performance.
var DisableThreadChecks = true
const DisableThreadChecks = true
2 changes: 1 addition & 1 deletion internal/build/migrated_notfynedo.go
Original file line number Diff line number Diff line change
@@ -3,4 +3,4 @@
package build

// DisableThreadChecks set to false enables the thread safety checks for logging of incorrect usage.
var DisableThreadChecks = false
const DisableThreadChecks = false