Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions phpthread.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,16 @@ func (thread *phpThread) shutdown() {
}
}

// restart the underlying PHP thread
func (thread *phpThread) restart() {
if !thread.state.requestSafeStateChange(stateRestarting) {
return
}
close(thread.drainChan)
thread.state.waitFor(stateYielding)
thread.drainChan = make(chan struct{})
}

// change the thread handler safely
// must be called from outside the PHP thread
func (thread *phpThread) setHandler(handler threadHandler) {
Expand Down
10 changes: 1 addition & 9 deletions worker.go
Original file line number Diff line number Diff line change
Expand Up @@ -148,16 +148,8 @@ func drainWorkerThreads() []*phpThread {
worker.threadMutex.RLock()
ready.Add(len(worker.threads))
for _, thread := range worker.threads {
if !thread.state.requestSafeStateChange(stateRestarting) {
ready.Done()
// no state change allowed == thread is shutting down
// we'll proceed to restart all other threads anyways
continue
}
close(thread.drainChan)
drainedThreads = append(drainedThreads, thread)
go func(thread *phpThread) {
thread.state.waitFor(stateYielding)
thread.restart()
ready.Done()
}(thread)
}
Expand Down
Loading