KeyedMutex
A keyed, suspend-friendly mutex for Kotlin Multiplatform.
Guarantees mutual exclusion per key, without blocking threads. API mirrors the kotlinx.coroutines Mutex:
lock(key, owner)
tryLock(key, owner)
unlock(key, owner)
withLock(key, owner) { ... }
Internals:
A per-key entry holds a Mutex and a reference count (holders/waiters).
We increment refs before suspending for lock(key) so entries aren’t removed while waiting.
Cleanup removes the entry only when refs == 0 and the mutex is not locked.