mirror of https://github.com/Icinga/icinga2.git
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:
commit
020bd86b4c
|
@ -23,6 +23,7 @@
|
||||||
#include "base/i2-base.hpp"
|
#include "base/i2-base.hpp"
|
||||||
#include "base/debug.hpp"
|
#include "base/debug.hpp"
|
||||||
#include <boost/smart_ptr/intrusive_ptr.hpp>
|
#include <boost/smart_ptr/intrusive_ptr.hpp>
|
||||||
|
#include <cstddef>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
using boost::intrusive_ptr;
|
using boost::intrusive_ptr;
|
||||||
|
@ -212,6 +213,7 @@ private:
|
||||||
# else /* _WIN32 */
|
# else /* _WIN32 */
|
||||||
mutable DWORD m_LockOwner;
|
mutable DWORD m_LockOwner;
|
||||||
# endif /* _WIN32 */
|
# endif /* _WIN32 */
|
||||||
|
mutable size_t m_LockCount = 0;
|
||||||
#endif /* I2_DEBUG */
|
#endif /* I2_DEBUG */
|
||||||
|
|
||||||
friend struct ObjectLock;
|
friend struct ObjectLock;
|
||||||
|
|
|
@ -90,11 +90,13 @@ void ObjectLock::Lock()
|
||||||
m_Locked = true;
|
m_Locked = true;
|
||||||
|
|
||||||
#ifdef I2_DEBUG
|
#ifdef I2_DEBUG
|
||||||
|
if (++m_Object->m_LockCount == 1u) {
|
||||||
# ifdef _WIN32
|
# ifdef _WIN32
|
||||||
InterlockedExchange(&m_Object->m_LockOwner, GetCurrentThreadId());
|
InterlockedExchange(&m_Object->m_LockOwner, GetCurrentThreadId());
|
||||||
# else /* _WIN32 */
|
# 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 /* _WIN32 */
|
||||||
|
}
|
||||||
#endif /* I2_DEBUG */
|
#endif /* I2_DEBUG */
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -120,7 +122,7 @@ void ObjectLock::Spin(unsigned int it)
|
||||||
void ObjectLock::Unlock()
|
void ObjectLock::Unlock()
|
||||||
{
|
{
|
||||||
#ifdef I2_DEBUG
|
#ifdef I2_DEBUG
|
||||||
if (m_Locked) {
|
if (m_Locked && !--m_Object->m_LockCount) {
|
||||||
# ifdef _WIN32
|
# ifdef _WIN32
|
||||||
InterlockedExchange(&m_Object->m_LockOwner, 0);
|
InterlockedExchange(&m_Object->m_LockOwner, 0);
|
||||||
# else /* _WIN32 */
|
# else /* _WIN32 */
|
||||||
|
|
Loading…
Reference in New Issue