Skip to content

Commit

Permalink
Bug 1616896 - inline ifdefs in SqliteMutex.h. r=asuth
Browse files Browse the repository at this point in the history
Differential Revision: https://phabricator.services.mozilla.com/D63515

--HG--
extra : moz-landing-system : lando
  • Loading branch information
mak77 committed Feb 20, 2020
1 parent 636a4b4 commit 8eb5703
Showing 1 changed file with 22 additions and 27 deletions.
49 changes: 22 additions & 27 deletions storage/SQLiteMutex.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand All @@ -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); }

/**
* Releases the mutex.
*/
void unlock() { ::sqlite3_mutex_leave(mMutex); }

/**
* Asserts that the current thread owns the mutex.
*/
void assertCurrentThreadOwns() {}

/**
* Asserts that the current thread does not own the mutex.
*/
void assertNotCurrentThreadOwns() {}

#else
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() {
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() {
MOZ_ASSERT(mMutex, "No mutex associated with this wrapper!");
MOZ_ASSERT(sqlite3_mutex_held(mMutex),
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() {
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;
Expand Down

0 comments on commit 8eb5703

Please sign in to comment.