Files
archived-frankenphp/threadinactive.go
Kévin Dunglas 8341cc98c6 refactor: rely on context.Context for log/slog and others (#1969)
* refactor: rely on context.Context for log/slog and others

* optimize

* refactor

* Apply suggestion from @Copilot

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>

* fix watcher-skip

* better globals handling

* fix

---------

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
2025-11-17 16:32:23 +01:00

57 lines
1.4 KiB
Go

package frankenphp
import "context"
// representation of a thread with no work assigned to it
// implements the threadHandler interface
// each inactive thread weighs around ~350KB
// keeping threads at 'inactive' will consume more memory, but allow a faster transition
type inactiveThread struct {
thread *phpThread
}
func convertToInactiveThread(thread *phpThread) {
thread.setHandler(&inactiveThread{thread: thread})
}
func (handler *inactiveThread) beforeScriptExecution() string {
thread := handler.thread
switch thread.state.get() {
case stateTransitionRequested:
return thread.transitionToNewHandler()
case stateBooting, stateTransitionComplete:
thread.state.set(stateInactive)
// wait for external signal to start or shut down
thread.state.markAsWaiting(true)
thread.state.waitFor(stateTransitionRequested, stateShuttingDown)
thread.state.markAsWaiting(false)
return handler.beforeScriptExecution()
case stateShuttingDown:
// signal to stop
return ""
}
panic("unexpected state: " + thread.state.name())
}
func (handler *inactiveThread) afterScriptExecution(int) {
panic("inactive threads should not execute scripts")
}
func (handler *inactiveThread) frankenPHPContext() *frankenPHPContext {
return nil
}
func (handler *inactiveThread) context() context.Context {
return nil
}
func (handler *inactiveThread) name() string {
return "Inactive PHP Thread"
}