Main-locked threads are panic wrapped
This commit is contained in:
parent
f97f5010e2
commit
5d25b3fb9a
32
phases.go
32
phases.go
@ -234,9 +234,9 @@ func (this *environment) phase70Running() bool {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
result := make(chan bool)
|
bodyReturn := make(chan bool)
|
||||||
go func() {
|
go func() {
|
||||||
result <- this.phase70RunningBody()
|
bodyReturn <- this.phase70RunningBody()
|
||||||
if this.main != nil {
|
if this.main != nil {
|
||||||
shutdownCtx, done := context.WithTimeout(
|
shutdownCtx, done := context.WithTimeout(
|
||||||
context.Background(),
|
context.Background(),
|
||||||
@ -247,19 +247,12 @@ func (this *environment) phase70Running() bool {
|
|||||||
}
|
}
|
||||||
}()
|
}()
|
||||||
|
|
||||||
|
mainReturn := false
|
||||||
if this.main != nil {
|
if this.main != nil {
|
||||||
mainActor := this.main.(Actor)
|
mainReturn = this.phase70_2MainBind()
|
||||||
if this.Verb() { log.Printf("(i) (70) binding %s to main thread", mainActor.Type()) }
|
|
||||||
runtime.LockOSThread()
|
|
||||||
defer runtime.UnlockOSThread()
|
|
||||||
err := this.main.RunMain()
|
|
||||||
if err != nil {
|
|
||||||
log.Printf("XXX [%s] main thread failed: %v", mainActor.Type(), err)
|
|
||||||
}
|
|
||||||
if this.Verb() { log.Printf("(i) (70) main thread exited") }
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return <- result
|
return <- bodyReturn && mainReturn
|
||||||
}
|
}
|
||||||
|
|
||||||
func (this *environment) phase70RunningBody() bool {
|
func (this *environment) phase70RunningBody() bool {
|
||||||
@ -294,6 +287,21 @@ func (this *environment) phase70RunningBody() bool {
|
|||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (this *environment) phase70_2MainBind() bool{
|
||||||
|
mainActor := this.main.(Actor)
|
||||||
|
if this.Verb() { log.Printf("... (70.2) binding %s to main thread", mainActor.Type()) }
|
||||||
|
runtime.LockOSThread()
|
||||||
|
if this.Verb() { log.Printf(".// (70.2) main thread bind complete") }
|
||||||
|
defer runtime.UnlockOSThread()
|
||||||
|
err := panicWrap(this.main.RunMain)
|
||||||
|
if err != nil {
|
||||||
|
log.Printf("XXX [%s] main thread failed: %v", mainActor.Type(), err)
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
if this.Verb() { log.Printf("(i) (70.2) main thread exited") }
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
func (this *environment) phase70_5Trimming() bool {
|
func (this *environment) phase70_5Trimming() bool {
|
||||||
if this.Verb() { log.Println("... (70.5) trimming") }
|
if this.Verb() { log.Println("... (70.5) trimming") }
|
||||||
var trimmable []Trimmable
|
var trimmable []Trimmable
|
||||||
|
|||||||
32
util.go
32
util.go
@ -14,16 +14,34 @@ import "sync/atomic"
|
|||||||
import "unicode/utf8"
|
import "unicode/utf8"
|
||||||
import "runtime/debug"
|
import "runtime/debug"
|
||||||
|
|
||||||
func panicErr(message any, stack []byte) (err error) {
|
type panicError struct {
|
||||||
if panErr, ok := message.(error); ok {
|
wrapped error
|
||||||
err = panErr
|
stack []byte
|
||||||
|
}
|
||||||
|
|
||||||
|
func (this panicError) Error() string {
|
||||||
|
if this.stack == nil {
|
||||||
|
return this.wrapped.Error()
|
||||||
} else {
|
} else {
|
||||||
err = errors.New(fmt.Sprint(message))
|
return fmt.Sprintf("%v: %s", this.wrapped, this.stack)
|
||||||
}
|
}
|
||||||
if stack != nil {
|
|
||||||
err = fmt.Errorf("%w: %s", err, stack)
|
|
||||||
}
|
}
|
||||||
return err
|
|
||||||
|
func (this panicError) Unwrap() error {
|
||||||
|
return this.wrapped
|
||||||
|
}
|
||||||
|
|
||||||
|
func panicErr(message any, stack []byte) (err error) {
|
||||||
|
var wrapped error
|
||||||
|
if panErr, ok := message.(error); ok {
|
||||||
|
wrapped = panErr
|
||||||
|
} else {
|
||||||
|
wrapped = errors.New(fmt.Sprint(message))
|
||||||
|
}
|
||||||
|
return panicError {
|
||||||
|
wrapped: wrapped,
|
||||||
|
stack: stack,
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func defaul[T comparable](value, def T) T {
|
func defaul[T comparable](value, def T) T {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user