-
-
Notifications
You must be signed in to change notification settings - Fork 280
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* do not use caddy context * ensure all handles are cleaned up * do not export types * just panic when double deleting a handle * set the minimal capacity * remove micro-opt * move handle cleanup to just before we return from serveHttp * ensure we clean up cli scripts * handle cgi-mode free * micro-optimization: set initial capacity
- Loading branch information
1 parent
11711bb
commit 5bda50c
Showing
3 changed files
with
100 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
package frankenphp | ||
|
||
// #include <stdlib.h> | ||
import "C" | ||
import ( | ||
"runtime/cgo" | ||
"unsafe" | ||
) | ||
|
||
/* | ||
FrankenPHP is fairly complex because it shuffles handles/requests/contexts | ||
between C and Go. This simplifies the lifecycle management of per-request | ||
structures by allowing us to hold references until the end of the request | ||
and ensure they are always cleaned up. | ||
*/ | ||
|
||
// PointerList A list of pointers that can be freed at a later time | ||
type pointerList struct { | ||
Pointers []unsafe.Pointer | ||
} | ||
|
||
// HandleList A list of pointers that can be freed at a later time | ||
type handleList struct { | ||
Handles []cgo.Handle | ||
} | ||
|
||
// AddHandle Call when registering a handle for the very first time | ||
func (h *handleList) AddHandle(handle cgo.Handle) { | ||
h.Handles = append(h.Handles, handle) | ||
} | ||
|
||
// AddPointer Call when creating a request-level C pointer for the very first time | ||
func (p *pointerList) AddPointer(ptr unsafe.Pointer) { | ||
p.Pointers = append(p.Pointers, ptr) | ||
} | ||
|
||
// FreeAll frees all C pointers | ||
func (p *pointerList) FreeAll() { | ||
for _, ptr := range p.Pointers { | ||
C.free(ptr) | ||
} | ||
p.Pointers = nil // To avoid dangling pointers | ||
} | ||
|
||
// FreeAll frees all handles | ||
func (h *handleList) FreeAll() { | ||
for _, p := range h.Handles { | ||
p.Delete() | ||
} | ||
} | ||
|
||
// Pointers Get a new list of pointers | ||
func Pointers() *pointerList { | ||
return &pointerList{ | ||
Pointers: make([]unsafe.Pointer, 0), | ||
} | ||
} | ||
|
||
// Handles Get a new list of handles | ||
func Handles() *handleList { | ||
return &handleList{ | ||
Handles: make([]cgo.Handle, 0, 8), | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters