#include "base/exception.hpp"
#include <boost/lexical_cast.hpp>
#include <boost/thread/recursive_mutex.hpp>
+#include <thread>
using namespace icinga;
Object::Object()
{
m_References.store(0);
+ m_LockOwner.store(decltype(m_LockOwner.load())());
}
/**
*/
bool Object::OwnsLock() const
{
-#ifdef _WIN32
- DWORD tid = InterlockedExchangeAdd(&m_LockOwner, 0);
-
- return (tid == GetCurrentThreadId());
-#else /* _WIN32 */
- pthread_t tid = __sync_fetch_and_add(&m_LockOwner, 0);
-
- return (tid == pthread_self());
-#endif /* _WIN32 */
+ return m_LockOwner.load() == std::this_thread::get_id();
}
#endif /* I2_DEBUG */
#include <atomic>
#include <cstddef>
#include <cstdint>
+#include <thread>
#include <vector>
using boost::intrusive_ptr;
mutable uintptr_t m_Mutex{0};
#ifdef I2_DEBUG
-# ifndef _WIN32
- mutable pthread_t m_LockOwner;
-# else /* _WIN32 */
- mutable DWORD m_LockOwner;
-# endif /* _WIN32 */
+ mutable std::atomic<std::thread::id> m_LockOwner;
mutable size_t m_LockCount = 0;
#endif /* I2_DEBUG */
#include "base/objectlock.hpp"
#include <boost/thread/recursive_mutex.hpp>
+#include <thread>
using namespace icinga;
#ifdef I2_DEBUG
if (++m_Object->m_LockCount == 1u) {
-# ifdef _WIN32
- InterlockedExchange(&m_Object->m_LockOwner, GetCurrentThreadId());
-# else /* _WIN32 */
- __sync_lock_test_and_set(&m_Object->m_LockOwner, pthread_self());
-# endif /* _WIN32 */
+ m_Object->m_LockOwner.store(std::this_thread::get_id());
}
#endif /* I2_DEBUG */
}
{
#ifdef I2_DEBUG
if (m_Locked && !--m_Object->m_LockCount) {
-# ifdef _WIN32
- InterlockedExchange(&m_Object->m_LockOwner, 0);
-# else /* _WIN32 */
- __sync_lock_release(&m_Object->m_LockOwner);
-# endif /* _WIN32 */
+ m_Object->m_LockOwner.store(decltype(m_Object->m_LockOwner.load())());
}
#endif /* I2_DEBUG */