SIGN IN SIGN UP

Use Mutex instead of ReentrantLock to serialize trigger sync

In TriggerBasedInvalidationTracker, syncTriggers() calls ObservedTableStates.onSync() to synchronize database triggers when table observers are added or removed. Because onSync() is inlined with a suspending action lambda, the coroutine can suspend and resume on a different thread. Either due to dispatcher behavior or because of a suspending driver. Using a ReentrantLock is dangerous because it will throw IllegalMonitorStateException when unlock() was called on a different thread upon resumption.

This change replaces onSyncLock (ReentrantLock) with onSyncMutex (Mutex), ensuring the lock is coroutine based and safely released across suspension points and thread boundaries. This is extending the same strategy done on the connection pool for suspending drivers (Id14035164a67d8f2f87b89bb0c2b290550693a4f).

Bug: 543285472
Bug: 553140228
Test: ObservedTableStatesTest, SuspendingQueryTest
Relnote: Fix a regression that would cause Room to throw an `IllegalMonitorStateException` when using ``@Transaction` wrapper DAO functions.
Change-Id: I996d95c6a7f9392b8d073027c8d970a607f78870
D
Daniel Santiago Rivera committed
c9a8904a1e136a084901187de6c609842d29cb2e
Parent: b5393ee