setHandler changes the thread handler safely must be called from outside the PHP thread
(handler threadHandler)
| 138 | // setHandler changes the thread handler safely |
| 139 | // must be called from outside the PHP thread |
| 140 | func (thread *phpThread) setHandler(handler threadHandler) { |
| 141 | thread.handlerMu.Lock() |
| 142 | defer thread.handlerMu.Unlock() |
| 143 | |
| 144 | if !thread.state.RequestSafeStateChange(state.TransitionRequested) { |
| 145 | // no state change allowed == shutdown or done |
| 146 | return |
| 147 | } |
| 148 | |
| 149 | close(thread.drainChan) |
| 150 | |
| 151 | thread.state.WaitFor(state.TransitionInProgress) |
| 152 | thread.handler = handler |
| 153 | thread.drainChan = make(chan struct{}) |
| 154 | thread.state.Set(state.TransitionComplete) |
| 155 | } |
| 156 | |
| 157 | // transition to a new handler safely |
| 158 | // is triggered by setHandler and executed on the PHP thread |