From 593eeeb8ed983b4c145110d8e3652545beeb84b1 Mon Sep 17 00:00:00 2001 From: Valiantsin Dzerakh Date: Wed, 18 Nov 2026 18:08:44 +0300 Subject: [PATCH] The lock order comments name the new edge: mirror_sync and mirror_create take shadow_lock under mirror_lock Co-Authored-By: Claude Opus 5.5 --- runtime/vk_memory.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/runtime/vk_memory.c b/runtime/vk_memory.c index 8704dc60..2ca18b17 100644 --- a/runtime/vk_memory.c +++ b/runtime/vk_memory.c @@ -1000,7 +1000,7 @@ static int query_stamp(uint64_t lo, uint64_t hi, uint32_t g) { // skips the pending ranges in the CPU copy and copies them back whole, as before. // TOTK_SHADOW=1/0 (shadow in totk.ini) forces the mode on or off; the default is on for Linux and Wine. typedef struct { uint64_t lo, hi; uint8_t *base; int refs; } SRange; -static PlatMutex shadow_lock = PLAT_MUTEX_INIT; // after pool_lock; before gen_lock +static PlatMutex shadow_lock = PLAT_MUTEX_INIT; // after mirror_lock and pool_lock; before gen_lock static PoolRec **stouch; // shadow_lock: pools resolved since the last sync static int nstouch, cstouch; static SRange *spend; // shadow_lock: distinct GPU writes recorded and not copied back yet @@ -1583,7 +1583,8 @@ static PlatMutex flush_lock = PLAT_MUTEX_INIT; static int flush_cap = FLUSH_RANGES; // ranges a pool keeps; 1 with TOTK_FLUSH_SPAN=1 // The first uses of a submission's mirrors, the copies they queue, the GPU writes noted and their snapshots (pend, wbl, snl, mrep): threads // recording chunks of one submission take it. A mirror synced in this submission is read without it (vk_mem_use): its -// acc_sub is stored last. Before pool_lock, gen_lock and flush_lock. +// acc_sub is stored last. Before pool_lock, shadow_lock (mirror_sync and mirror_create touch the shadow), gen_lock and +// flush_lock. static PlatMutex mirror_lock = PLAT_MUTEX_INIT; typedef struct {