-
-
Notifications
You must be signed in to change notification settings - Fork 259
/
thread-inactive.go
45 lines (38 loc) · 1.15 KB
/
thread-inactive.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
package frankenphp
import (
"net/http"
)
// representation of a thread with no work assigned to it
// implements the threadHandler interface
type inactiveThread struct {
thread *phpThread
}
func convertToInactiveThread(thread *phpThread) {
if thread.handler == nil {
thread.handler = &inactiveThread{thread: thread}
return
}
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.waitFor(stateTransitionRequested, stateShuttingDown)
return handler.beforeScriptExecution()
case stateShuttingDown:
// signal to stop
return ""
}
panic("unexpected state: " + thread.state.name())
}
func (thread *inactiveThread) afterScriptExecution(exitStatus int) {
panic("inactive threads should not execute scripts")
}
func (thread *inactiveThread) getActiveRequest() *http.Request {
panic("inactive threads have no requests")
}