Merge pull request #6408 from Icinga/bugfix/objectlock-unlock-m_lockowner

ObjectLock#Unlock(): don't reset m_Object->m_LockOwner too early
This commit is contained in:
Michael Friedrich 2018-07-26 10:02:26 +02:00 committed by GitHub
commit 020bd86b4c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 7 additions and 3 deletions

View File

@ -23,6 +23,7 @@
#include "base/i2-base.hpp"
#include "base/debug.hpp"
#include <boost/smart_ptr/intrusive_ptr.hpp>
#include <cstddef>
#include <vector>
using boost::intrusive_ptr;
@ -212,6 +213,7 @@ private:
# else /* _WIN32 */
mutable DWORD m_LockOwner;
# endif /* _WIN32 */
mutable size_t m_LockCount = 0;
#endif /* I2_DEBUG */
friend struct ObjectLock;

View File

@ -90,11 +90,13 @@ void ObjectLock::Lock()
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 */
}
@ -120,7 +122,7 @@ void ObjectLock::Spin(unsigned int it)
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 */