#include "base/i2-base.hpp"
#include "base/debug.hpp"
#include <boost/smart_ptr/intrusive_ptr.hpp>
+#include <cstddef>
#include <vector>
using boost::intrusive_ptr;
# else /* _WIN32 */
mutable DWORD m_LockOwner;
# endif /* _WIN32 */
+ mutable size_t m_LockCount = 0;
#endif /* I2_DEBUG */
friend struct ObjectLock;
m_Locked = true;
#ifdef I2_DEBUG
+ if (++m_Object->m_LockCount == 1u) {
# ifdef _WIN32
- InterlockedExchange(&m_Object->m_LockOwner, GetCurrentThreadId());
+ InterlockedExchange(&m_Object->m_LockOwner, GetCurrentThreadId());
# else /* _WIN32 */
- __sync_lock_test_and_set(&m_Object->m_LockOwner, pthread_self());
+ __sync_lock_test_and_set(&m_Object->m_LockOwner, pthread_self());
# endif /* _WIN32 */
+ }
#endif /* I2_DEBUG */
}
void ObjectLock::Unlock()
{
#ifdef I2_DEBUG
- if (m_Locked) {
+ if (m_Locked && !--m_Object->m_LockCount) {
# ifdef _WIN32
InterlockedExchange(&m_Object->m_LockOwner, 0);
# else /* _WIN32 */