refactor: removes context on the C side (#1404)

This commit is contained in:
Alexander Stecher
2025-03-10 08:44:03 +01:00
committed by GitHub
parent 09b8219ad4
commit f50248a7d2
13 changed files with 402 additions and 403 deletions
+13 -6
View File
@@ -4,7 +4,6 @@ package frankenphp
// #include "frankenphp.h"
import "C"
import (
"net/http"
"runtime"
"sync"
"unsafe"
@@ -17,7 +16,7 @@ import (
type phpThread struct {
runtime.Pinner
threadIndex int
requestChan chan *http.Request
requestChan chan *frankenPHPContext
drainChan chan struct{}
handlerMu sync.Mutex
handler threadHandler
@@ -30,13 +29,13 @@ type threadHandler interface {
name() string
beforeScriptExecution() string
afterScriptExecution(exitStatus int)
getActiveRequest() *http.Request
getRequestContext() *frankenPHPContext
}
func newPHPThread(threadIndex int) *phpThread {
return &phpThread{
threadIndex: threadIndex,
requestChan: make(chan *http.Request),
requestChan: make(chan *frankenPHPContext),
state: newThreadState(),
}
}
@@ -59,6 +58,7 @@ func (thread *phpThread) boot() {
if !C.frankenphp_new_php_thread(C.uintptr_t(thread.threadIndex)) {
logger.Panic("unable to create thread", zap.Int("threadIndex", thread.threadIndex))
}
thread.state.waitFor(stateInactive)
}
@@ -103,8 +103,15 @@ func (thread *phpThread) transitionToNewHandler() string {
return thread.handler.beforeScriptExecution()
}
func (thread *phpThread) getActiveRequest() *http.Request {
return thread.handler.getActiveRequest()
func (thread *phpThread) getRequestContext() *frankenPHPContext {
return thread.handler.getRequestContext()
}
func (thread *phpThread) name() string {
thread.handlerMu.Lock()
name := thread.handler.name()
thread.handlerMu.Unlock()
return name
}
// Pin a string that is not null-terminated