Bug 1616896 - inline ifdefs in SqliteMutex.h. r=asuth

Differential Revision: https://phabricator.services.mozilla.com/D63515

--HG--
extra : moz-landing-system : lando
This commit is contained in:
Marco Bonardo 2020-02-20 18:40:27 +00:00
Родитель 636a4b4b19
Коммит 8eb5703927
1 изменённых файлов: 32 добавлений и 37 удалений

Просмотреть файл

@ -40,8 +40,8 @@ class SQLiteMutex : private BlockingResourceBase {
* The sqlite3_mutex that we are going to wrap.
*/
void initWithMutex(sqlite3_mutex* aMutex) {
NS_ASSERTION(aMutex, "You must pass in a valid mutex!");
NS_ASSERTION(!mMutex, "A mutex has already been set for this!");
MOZ_ASSERT(aMutex, "You must pass in a valid mutex!");
MOZ_ASSERT(!mMutex, "A mutex has already been set for this!");
mMutex = aMutex;
}
@ -51,60 +51,55 @@ class SQLiteMutex : private BlockingResourceBase {
*/
void destroy() { mMutex = NULL; }
#if !defined(DEBUG) || defined(MOZ_SYSTEM_SQLITE)
/**
* Acquires the mutex.
*/
void lock() { ::sqlite3_mutex_enter(mMutex); }
void lock() {
MOZ_ASSERT(mMutex, "No mutex associated with this wrapper!");
#if defined(DEBUG) && !defined(MOZ_SYSTEM_SQLITE)
// While SQLite Mutexes may be recursive, in our own code we do not want to
// treat them as such.
CheckAcquire();
#endif
::sqlite3_mutex_enter(mMutex);
#if defined(DEBUG) && !defined(MOZ_SYSTEM_SQLITE)
Acquire(); // Call is protected by us holding the mutex.
#endif
}
/**
* Releases the mutex.
*/
void unlock() { ::sqlite3_mutex_leave(mMutex); }
void unlock() {
MOZ_ASSERT(mMutex, "No mutex associated with this wrapper!");
#if defined(DEBUG) && !defined(MOZ_SYSTEM_SQLITE)
// While SQLite Mutexes may be recursive, in our own code we do not want to
// treat them as such.
Release(); // Call is protected by us holding the mutex.
#endif
::sqlite3_mutex_leave(mMutex);
}
/**
* Asserts that the current thread owns the mutex.
*/
void assertCurrentThreadOwns() {}
void assertCurrentThreadOwns() {
MOZ_ASSERT(mMutex, "No mutex associated with this wrapper!");
MOZ_ASSERT(::sqlite3_mutex_held(mMutex),
"Mutex is not held, but we expect it to be!");
}
/**
* Asserts that the current thread does not own the mutex.
*/
void assertNotCurrentThreadOwns() {}
#else
void lock() {
MOZ_ASSERT(mMutex, "No mutex associated with this wrapper!");
// While SQLite Mutexes may be recursive, in our own code we do not want to
// treat them as such.
CheckAcquire();
::sqlite3_mutex_enter(mMutex);
Acquire(); // Call is protected by us holding the mutex.
}
void unlock() {
MOZ_ASSERT(mMutex, "No mutex associated with this wrapper!");
// While SQLite Mutexes may be recursive, in our own code we do not want to
// treat them as such.
Release(); // Call is protected by us holding the mutex.
::sqlite3_mutex_leave(mMutex);
}
void assertCurrentThreadOwns() {
MOZ_ASSERT(mMutex, "No mutex associated with this wrapper!");
MOZ_ASSERT(sqlite3_mutex_held(mMutex),
"Mutex is not held, but we expect it to be!");
}
void assertNotCurrentThreadOwns() {
MOZ_ASSERT(mMutex, "No mutex associated with this wrapper!");
MOZ_ASSERT(sqlite3_mutex_notheld(mMutex),
MOZ_ASSERT(::sqlite3_mutex_notheld(mMutex),
"Mutex is held, but we expect it to not be!");
}
#endif // ifndef DEBUG
private:
sqlite3_mutex* mMutex;