@@ -18,6 +18,12 @@ using namespace mgb; | |||||
#if MGB_THREAD_SAFE | #if MGB_THREAD_SAFE | ||||
const std::thread::id RecursiveSpinlock::sm_none_owner = std::thread::id(); | const std::thread::id RecursiveSpinlock::sm_none_owner = std::thread::id(); | ||||
//! why not use initializer_list for global var, detail: | |||||
//! MGE-1738 | |||||
RecursiveSpinlock::RecursiveSpinlock() { | |||||
m_owner = sm_none_owner; | |||||
} | |||||
void RecursiveSpinlock::lock() { | void RecursiveSpinlock::lock() { | ||||
auto tid = std::this_thread::get_id(); | auto tid = std::this_thread::get_id(); | ||||
if (m_owner.load(std::memory_order_relaxed) != tid) { | if (m_owner.load(std::memory_order_relaxed) != tid) { | ||||
@@ -33,15 +33,15 @@ class Spinlock final: public NonCopyableObj { | |||||
}; | }; | ||||
//! recursive spinlock | //! recursive spinlock | ||||
class RecursiveSpinlock final: public NonCopyableObj { | |||||
class RecursiveSpinlock final : public NonCopyableObj { | |||||
static const std::thread::id sm_none_owner; | static const std::thread::id sm_none_owner; | ||||
std::atomic<std::thread::id> m_owner{sm_none_owner}; | |||||
std::atomic<std::thread::id> m_owner; | |||||
size_t m_recur_count = 0; | size_t m_recur_count = 0; | ||||
public: | |||||
void lock(); | |||||
void unlock(); | |||||
public: | |||||
RecursiveSpinlock(); | |||||
void lock(); | |||||
void unlock(); | |||||
}; | }; | ||||
} // namespace mgb | } // namespace mgb | ||||