Added AssertLockNotHeld().
I kept the annotation on the Cleanup() method, even though it is called only from the constructor and the destructor in case it gets called from elsewhere in the future.
This looks a bit strange:
Mutex m1;
int global_counter GUARDED_BY(m1){0};
void f() EXCLUSIVE_LOCKS_REQUIRED(!m1)
{
AssertLockNotHeld(m1);
LOCK(m1);
++global_counter;
}
SQLiteDatabase::SQLiteDatabase()
{
LOCK(m1);
// ok!?
f();
void SQLiteDatabase::Open() // any other method
{
LOCK(m1);
// error: cannot call function 'f' while mutex 'm1' is held [-Werror,-Wthread-safety-analysis]
f();
I understand annotations on the constructor are disabled, but the above is more than that. Are constructors treated like NO_THREAD_SAFETY_ANALYSIS?