Skip to content

Commit a6c2e76

Browse files
danieljesusclaude
andcommitted
[local] GpuModifiedSnapshot: publish the rebuilt snapshot before clearing the stale flag
The lazy rebuild cleared _gpuModifiedSnapshotStale before writing the new snapshot, so a lock-free HasGpuDirtyBytes that saw the flag clear during the O(n) rebuild returned the previous snapshot. HasGpuDirtyBytes_StaysExactForReadersWhileRangesChange failed 5/5 (wrong=2..1113); now 10/10 and the Libs suite is green. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01JKcqXLB989bbHkxLTmvnCv
1 parent 8b0449e commit a6c2e76

1 file changed

Lines changed: 2 additions & 1 deletion

File tree

‎src/SharpEmu.Libs/Gpu/Buffers/GuestBufferCache.cs‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -454,9 +454,10 @@ private SpanSnapshot GpuModifiedSnapshot()
454454
_gpuModifiedGate.EnterReadLock();
455455
try
456456
{
457-
_gpuModifiedSnapshotStale = false;
457+
// Publish before clearing the flag: a lock-free reader that sees it clear must also see this snapshot.
458458
var snapshot = _gpuModifiedRanges.Snapshot();
459459
Volatile.Write(ref _gpuModifiedSnapshot, snapshot);
460+
_gpuModifiedSnapshotStale = false;
460461
return snapshot;
461462
}
462463
finally

0 commit comments

Comments
 (0)