mirror of
https://github.com/MobileGL-Dev/MobileGL
synced 2026-11-21 00:41:57 +09:00
[Feature] (P14): state ownership - multi-session, multi-context, share groups
Breaks the one process = one server = one session = one context equation
that the whole stack's correctness used to rest on. Design and per-slice
shape: docs/Disaggregated/design/11-state-ownership.md.
S1 wire: bind_context ring record (opcode 84) announces the current
context at the make-current edge; CreateContext/DestroyContext join the
SurfaceOp control frames; control revision 5 -> 6; the server keeps a
per-session token table and refuses unknown tokens by name.
S2 server: SessionRuntime per session with thread-scoped resolution
(singletons become fallbacks), per-thread gPipeInputs, per-session latch
domains, per-thread segment resolvers; the in-process unix supervisor
serves up to MOBILEGL_IPC_INPROC_MAX_SESSIONS (16) concurrent sessions;
surface mode is declared per session and the display lease refuses a
second on-screen session by name.
S3 frontend: ShareGroupState owns the shared object stores and name
generators (buffer/texture/renderbuffer/sampler/program), GLContext keeps
per-context bindings/errors/container objects; pGLContext becomes
thread-local with a process default context preserving the single-context
world verbatim; eglCreateContext builds a real GLContext and joins the
sharing context's group.
S4 backend: native EGL tuples keyed by (session, context token);
InitDisplayAndContext's unconditional teardown is gone - creating a
second context or surface no longer destroys the first; eglCreateContext
sharing is wired to the native driver; bind_context is the native switch
point.
S5 applier: MGPipeApplierState splits into MGPipeObjectRecords (per
share group) and MGPipeWorkingState (per context), resolved through a
{session, token} registry with a thread-local cached fast path.
Tests: MultiSessionTest (incl. two sessions x two contexts interleaved
with real clear/readback witnesses), ApplierOwnershipTest (with a
null-resolver negative control), ContextStateOwnershipTest,
ServerLoopEglTest native-context liveness; 99/99 of the acceptance set
green on the host build.
Known debts (documented in the design doc): twin registries still keyed
by handle alone, no per-record ContextSlot, process-global backend
generations, MakeCurrent dedup per current binding.
This commit is contained in:
@@ -62,8 +62,10 @@ namespace MobileGL::MG_Remote {
|
||||
// crash (ID-P7-1: "下一连接照常服务" is the supervisor's, not the latch's).
|
||||
//
|
||||
// WHERE IT IS ARMED, AND WHY ONLY THERE. ArmSessionLatch() is called by exactly one site:
|
||||
// ServerMain::RunSession, i.e. the spawn / TCP session child (with or without --serve), whose
|
||||
// process IS the session. Unarmed, SessionLatch IS SessionFail - same line, same abort - and
|
||||
// ServerMain::RunSession, i.e. a served session - the spawn / TCP session child (with or
|
||||
// without --serve), whose process IS the session, and (P14 S2) each session the in-process
|
||||
// display server runs, which arms ITS OWN latch domain so a fault there ends that session and
|
||||
// no other. Unarmed, SessionLatch IS SessionFail - same line, same abort - and
|
||||
// that is the answer everywhere else, deliberately:
|
||||
// * INPROC keeps Fatal. CONTRACT-P5's R-2 arms (rules A/B/C, the four honesty arms) are
|
||||
// Fatal{ProtocolCorruption} in the formal wording, and under inproc the client and the
|
||||
@@ -85,6 +87,10 @@ namespace MobileGL::MG_Remote {
|
||||
// Between sessions the latch is unarmed, so a fault there is a SessionFail - which in the
|
||||
// in-process shape takes the display Activity's process down with it: the crash isolation a
|
||||
// forked session child gave is what running in-process gives up (documented, D5).
|
||||
//
|
||||
// P14 S2: it now clears the CALLING THREAD'S DOMAIN (below), which between sessions is the
|
||||
// process default - a session that opened its own domain cannot leave a latch behind for the
|
||||
// next one to inherit, because the next one does not read that domain at all.
|
||||
void ResetSessionLatch();
|
||||
// True once the first fault has latched. One acquire load: DrainRing asks it before every pop.
|
||||
bool SessionLatched();
|
||||
@@ -95,6 +101,31 @@ namespace MobileGL::MG_Remote {
|
||||
// Every fault this armed process latched or declined after the first (>= 1 once latched).
|
||||
::std::uint64_t SessionLatchCount();
|
||||
|
||||
// ---- P14 S2: ONE LATCH DOMAIN PER SERVED SESSION ------------------------------------
|
||||
//
|
||||
// THE LATCH IS PER SESSION NOW, and that is a correctness requirement of serving several in
|
||||
// one process, not a tidy-up. Its three readers sit on a session's own threads - the apply
|
||||
// loop's park, DrainRing's per-pop check, ServerMain's control loop - so a latch raised by
|
||||
// session A used to stop session B's apply thread mid-ring and end B's control loop: one
|
||||
// peer's bad bytes took down its neighbours. ResetSessionLatch had the mirror problem: the
|
||||
// reap of a finished session cleared the latch a live one was standing on.
|
||||
//
|
||||
// A DOMAIN is the latch state, and a THREAD IS BOUND TO ONE. SessionRuntime opens a domain per
|
||||
// served session and ThreadSessionScope binds both of that session's threads to it. A thread
|
||||
// that has bound nothing uses DOMAIN 0, the process default - which is exactly the old
|
||||
// behaviour, and is what the client, the inproc one-process shape and every unit case get.
|
||||
//
|
||||
// 0 IS RESERVED FOR THE PROCESS DEFAULT and FatalLatchDomainOpen never returns it (0 on
|
||||
// exhaustion, which degrades to "shares the default" rather than to a crash).
|
||||
inline constexpr int kMaxLatchDomains = 64;
|
||||
int FatalLatchDomainOpen();
|
||||
// The domain's state goes; no thread may still be bound to it (the session's apply thread is
|
||||
// joined and its control thread's scope has been destroyed by then).
|
||||
void FatalLatchDomainClose(int domain);
|
||||
// Binds the CALLING THREAD to `domain`, returning the domain it was bound to before so a
|
||||
// scope can put it back.
|
||||
int FatalLatchDomainBind(int domain);
|
||||
|
||||
// The session child's exit status when its session ended on a latched fault. Distinct from
|
||||
// RunSession's other codes (64-74) so the supervisor's reap line names it; nonzero, so it is
|
||||
// counted in `sessionsFaulted` like every other fault.
|
||||
|
||||
Reference in New Issue
Block a user