File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -706,7 +706,7 @@ func go_is_context_done(threadIndex C.uintptr_t) C.bool {
706706//export go_schedule_opcache_reset
707707func go_schedule_opcache_reset (threadIndex C.uintptr_t ) C.bool {
708708 if isOpcacheResetting .CompareAndSwap (false , true ) {
709- restartThreadsForOpcacheReset (nil )
709+ restartThreadsForOpcacheReset (phpThreads [ threadIndex ] )
710710 return C .bool (true )
711711 }
712712
@@ -737,19 +737,31 @@ func restartThreadsForOpcacheReset(exceptThisThread *phpThread) {
737737 thread .state .Set (state .Restarting )
738738 close (thread .drainChan )
739739
740+ if thread == exceptThisThread {
741+ continue
742+ }
743+
740744 wg .Go (func () {
741745 thread .state .WaitFor (state .Yielding )
742746 })
743747 }
744748 }
745749
746- // other threads may not parse new scripts while this thread is scheduling an opcache_reset
747- // sleeping a bit here makes this much less likely to happen
748- // waiting for all other threads to drain first can potentially deadlock
749- time .Sleep (100 * time .Millisecond )
750-
750+ done := make (chan struct {})
751751 go func () {
752752 wg .Wait ()
753+ close (done )
754+ }()
755+
756+ select {
757+ case <- done :
758+ // all other threads are drained
759+ case <- time .After (time .Second ):
760+ // probably a deadlock, continue anyway and hope for the best
761+ }
762+
763+ go func () {
764+ exceptThisThread .state .WaitFor (state .Yielding )
753765 for _ , thread := range threadsToRestart {
754766 thread .drainChan = make (chan struct {})
755767 thread .state .Set (state .Ready )
You can’t perform that action at this time.
0 commit comments