-
Notifications
You must be signed in to change notification settings - Fork 439
Expand file tree
/
Copy paththreadinactive.go
More file actions
60 lines (45 loc) · 1.44 KB
/
threadinactive.go
File metadata and controls
60 lines (45 loc) · 1.44 KB
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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
package frankenphp
import (
"context"
"github.com/dunglas/frankenphp/internal/state"
)
// 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 state.TransitionRequested:
return thread.transitionToNewHandler()
case state.Booting, state.TransitionComplete:
thread.state.Set(state.Inactive)
// wait for external signal to start or shut down
thread.state.MarkAsWaiting(true)
thread.state.WaitFor(state.TransitionRequested, state.ShuttingDown)
thread.state.MarkAsWaiting(false)
return handler.beforeScriptExecution()
case state.ShuttingDown:
// 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 globalCtx
}
func (handler *inactiveThread) name() string {
return "Inactive PHP Thread"
}