The old macro expanded to two statements (mutex_lock + DEFER unlock).
In an unbraced if/else only the lock would be conditional while the
DEFER always executed — a latent double-unlock / unbalanced-unlock bug.
Add ScopedMutexLock to both debug and ndebug headers:
- debug: stores __FILE__/__func__/__LINE__ from the call site and
passes them to _mutex_lock/_mutex_unlock for diagnostics
- ndebug: lightweight wrapper around mutex_lock/mutex_unlock
Redefine mutex_lockguard to create a single uniquely-named
ScopedMutexLock variable (via __COUNTER__), making it safe in any
statement context. Remove the now-unused scope_guard include.
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>