aboutsummaryrefslogtreecommitdiffstats
path: root/serve
diff options
context:
space:
mode:
authoreunhhu <[email protected]>2026-10-04 14:43:11 +0100
committereunhhu <[email protected]>2026-10-04 14:43:11 +0100
commit8d0901ba060165ad0622a3be09b09e3acd4a8899 (patch)
tree96ec1e25c75a98a80a2a65f70951380f0deff94d /serve
parent540d4aef64eb5364a836615fbd44d321b029de3f (diff)
downloadpure-8d0901ba060165ad0622a3be09b09e3acd4a8899.tar.gz
pure-8d0901ba060165ad0622a3be09b09e3acd4a8899.zip
Let a view compute in its body, on a reader's own lists (018 stage 3)
Diffstat (limited to 'serve')
-rw-r--r--serve/serve.c7
1 files changed, 6 insertions, 1 deletions
diff --git a/serve/serve.c b/serve/serve.c
index 56a3430..b26ee68 100644
--- a/serve/serve.c
+++ b/serve/serve.c
@@ -424,7 +424,7 @@ struct App {
bool documents; /* the module serves /objects: it has show and edit */
bool owned; /* an owner runs it (states or outputs, or any of --apps); else the connection threads */
uint32_t show, edit;
- size_t memory; /* its budgets (0: none): what its states hold, */
+ _Atomic size_t memory; /* its budgets (0: none): what its states hold (read by its views' readers too), */
_Atomic uint64_t work; /* what an event or a view's evaluation may run */
size_t queue; /* the requests that may wait for its turn */
bool running; /* started (the main thread's word); else why says why */
@@ -1588,6 +1588,9 @@ static PureResult show_given(PureApp *app, const Route *route, size_t available,
if (status != PURE_OK && pure_app_view_fault(app) == PURE_FAULT_WORK) { /* past the work budget: 422 work */
answer->fault = PURE_FAULT_WORK;
status = PURE_LIMIT;
+ } else if (status != PURE_OK && pure_app_view_fault(app) == PURE_FAULT_MEMORY) { /* a body's lists past it: 503 memory */
+ answer->fault = PURE_FAULT_MEMORY;
+ status = PURE_BUDGET;
}
if (status == PURE_OK && !o.bytes && !(o.bytes = malloc(1))) o.failed = true; /* an empty value has a buffer too */
if (status == PURE_OK && o.failed) status = PURE_ALLOCATION;
@@ -2285,6 +2288,7 @@ static PureSnapshot *read_published(Host *host, App *app) {
PureApp *reader = &host->readers[app - apps];
if (snapshot) pure_app_read(reader, snapshot);
reader->work_budget = atomic_load_explicit(&app->work, memory_order_relaxed);
+ reader->memory = atomic_load_explicit(&app->memory, memory_order_relaxed); /* what a view's body may add to its own lists */
return snapshot;
}
@@ -2389,6 +2393,7 @@ static PureResult run_query(const Job *job, PureSnapshot *snapshot, Applied *a)
return PURE_CONFLICT;
}
pure_app_work(&reader, atomic_load_explicit(&job->route.app->work, memory_order_relaxed));
+ reader.memory = atomic_load_explicit(&job->route.app->memory, memory_order_relaxed);
reader.module = &held->module; /* the app's states, the query's views */
Route route = job->route;
route.target = (uint32_t)pure_module_view(&held->module, job->effect.key);