mirror of
https://github.com/tiennm99/ccs.git
synced 2026-07-17 10:17:05 +00:00
perf(config): replace busy-wait with Atomics.wait in lock retry
Use Atomics.wait for synchronous sleep instead of CPU-intensive busy-wait loop. This properly sleeps the thread without wasting cycles. Addresses code review feedback on PR #441.
This commit is contained in:
@@ -642,11 +642,10 @@ export function saveUnifiedConfig(config: UnifiedConfig): void {
|
|||||||
lockAcquired = true;
|
lockAcquired = true;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
// Wait before retry
|
// Synchronous sleep without CPU-intensive busy-wait
|
||||||
const start = Date.now();
|
// Uses Atomics.wait which properly sleeps the thread
|
||||||
while (Date.now() - start < retryDelayMs) {
|
// Note: saveUnifiedConfig is sync API with 19+ callers, converting to async not feasible
|
||||||
// Busy wait
|
Atomics.wait(new Int32Array(new SharedArrayBuffer(4)), 0, 0, retryDelayMs);
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!lockAcquired) {
|
if (!lockAcquired) {
|
||||||
|
|||||||
Reference in New Issue
Block a user