Add DEBUG_DOCUMENT_LOCKS to avoid logging doc locks

This commit is contained in:
David Capello 2016-10-03 13:24:59 -03:00
parent 7fb984b18d
commit a4277e8175

View File

@ -8,6 +8,10 @@
#include "config.h"
#endif
// Uncomment this line in case that you want TRACE() lock/unlock
// operations.
//#define DEBUG_DOCUMENT_LOCKS
#include "app/document.h"
#include "app/app.h"
@ -459,7 +463,10 @@ bool Document::lock(LockType lockType, int timeout)
if (m_read_locks == 0 && !m_write_lock) {
// We can start writting the sprite...
m_write_lock = true;
#ifdef DEBUG_DOCUMENT_LOCKS
TRACE("Document::lock: Locked <%d> to write\n", id());
#endif
return true;
}
break;
@ -471,15 +478,21 @@ bool Document::lock(LockType lockType, int timeout)
int delay = MIN(100, timeout);
timeout -= delay;
#ifdef DEBUG_DOCUMENT_LOCKS
TRACE("Document::lock: wait 100 msecs for <%d>\n", id());
#endif
base::this_thread::sleep_for(double(delay) / 1000.0);
}
else
break;
}
#ifdef DEBUG_DOCUMENT_LOCKS
TRACE("Document::lock: Cannot lock <%d> to %s (has %d read locks and %d write locks)\n",
id(), (lockType == ReadLock ? "read": "write"), m_read_locks, m_write_lock);
#endif
return false;
}
@ -493,7 +506,11 @@ bool Document::lockToWrite(int timeout)
ASSERT(!m_write_lock);
m_read_locks = 0;
m_write_lock = true;
#ifdef DEBUG_DOCUMENT_LOCKS
TRACE("Document::lockToWrite: Locked <%d> to write\n", id());
#endif
return true;
}
}
@ -502,15 +519,21 @@ bool Document::lockToWrite(int timeout)
int delay = MIN(100, timeout);
timeout -= delay;
#ifdef DEBUG_DOCUMENT_LOCKS
TRACE("Document::lockToWrite: wait 100 msecs for <%d>\n", id());
#endif
base::this_thread::sleep_for(double(delay) / 1000.0);
}
else
break;
}
#ifdef DEBUG_DOCUMENT_LOCKS
TRACE("Document::lockToWrite: Cannot lock <%d> to write (has %d read locks and %d write locks)\n",
id(), m_read_locks, m_write_lock);
#endif
return false;
}