mirror of
https://github.com/dunglas/frankenphp.git
synced 2025-12-24 13:38:11 +08:00
refactor: extract the state module and make the backoff error instead of panic
This PR: - moves state.go to its own module - moves the phpheaders test the phpheaders module - simplifies backoff.go - makes the backoff error instead of panic (so it can be tested) - removes some unused C structs
This commit is contained in:
committed by
GitHub
parent
16e2bbb969
commit
98573ed7c0
@@ -5,6 +5,8 @@ import (
|
||||
"runtime"
|
||||
"sync"
|
||||
"sync/atomic"
|
||||
|
||||
"github.com/dunglas/frankenphp/internal/state"
|
||||
)
|
||||
|
||||
// representation of a non-worker PHP thread
|
||||
@@ -13,7 +15,7 @@ import (
|
||||
type regularThread struct {
|
||||
contextHolder
|
||||
|
||||
state *threadState
|
||||
state *state.ThreadState
|
||||
thread *phpThread
|
||||
}
|
||||
|
||||
@@ -34,25 +36,27 @@ func convertToRegularThread(thread *phpThread) {
|
||||
|
||||
// beforeScriptExecution returns the name of the script or an empty string on shutdown
|
||||
func (handler *regularThread) beforeScriptExecution() string {
|
||||
switch handler.state.get() {
|
||||
case stateTransitionRequested:
|
||||
switch handler.state.Get() {
|
||||
case state.TransitionRequested:
|
||||
detachRegularThread(handler.thread)
|
||||
return handler.thread.transitionToNewHandler()
|
||||
|
||||
case stateTransitionComplete:
|
||||
handler.state.set(stateReady)
|
||||
case state.TransitionComplete:
|
||||
handler.thread.updateContext(false)
|
||||
handler.state.Set(state.Ready)
|
||||
|
||||
return handler.waitForRequest()
|
||||
|
||||
case stateReady:
|
||||
case state.Ready:
|
||||
return handler.waitForRequest()
|
||||
|
||||
case stateShuttingDown:
|
||||
case state.ShuttingDown:
|
||||
detachRegularThread(handler.thread)
|
||||
// signal to stop
|
||||
return ""
|
||||
}
|
||||
|
||||
panic("unexpected state: " + handler.state.name())
|
||||
panic("unexpected state: " + handler.state.Name())
|
||||
}
|
||||
|
||||
func (handler *regularThread) afterScriptExecution(_ int) {
|
||||
@@ -75,7 +79,7 @@ func (handler *regularThread) waitForRequest() string {
|
||||
// clear any previously sandboxed env
|
||||
clearSandboxedEnv(handler.thread)
|
||||
|
||||
handler.state.markAsWaiting(true)
|
||||
handler.state.MarkAsWaiting(true)
|
||||
|
||||
var ch contextHolder
|
||||
|
||||
@@ -89,7 +93,7 @@ func (handler *regularThread) waitForRequest() string {
|
||||
|
||||
handler.ctx = ch.ctx
|
||||
handler.contextHolder.frankenPHPContext = ch.frankenPHPContext
|
||||
handler.state.markAsWaiting(false)
|
||||
handler.state.MarkAsWaiting(false)
|
||||
|
||||
// set the scriptFilename that should be executed
|
||||
return handler.contextHolder.frankenPHPContext.scriptFilename
|
||||
|
||||
Reference in New Issue
Block a user