提交 469d0808 编写于 作者: M Megvii Engine Team

fix(asan/thread): fix asan issue

GitOrigin-RevId: 8e2b093fb1f696cc78091c28817fbada1feaa9d8
上级 eb826422
...@@ -18,6 +18,12 @@ using namespace mgb; ...@@ -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 { ...@@ -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: public:
RecursiveSpinlock();
void lock(); void lock();
void unlock(); void unlock();
}; };
} // namespace mgb } // namespace mgb
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册