Skip to content

Commit 19ac90d

Browse files
committed
Fix lifetime sanitizer false alarm.
1 parent 62f0328 commit 19ac90d

File tree

1 file changed

+15
-11
lines changed

1 file changed

+15
-11
lines changed

Common/Cpp/Concurrency/AsyncTask.cpp

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -38,25 +38,29 @@ AsyncTask::~AsyncTask(){
3838

3939

4040
void AsyncTask::report_cancelled() noexcept{
41+
{
4142
#ifdef PA_SANITIZE_AsyncTask
42-
auto scope = m_sanitizer.check_scope();
43+
auto scope = m_sanitizer.check_scope();
4344
#endif
44-
m_state.store(State::FINISHED, std::memory_order_release);
45-
{
46-
std::lock_guard<std::mutex> lg(m_lock);
45+
m_state.store(State::FINISHED, std::memory_order_release);
46+
{
47+
std::lock_guard<std::mutex> lg(m_lock);
48+
}
49+
m_cv.notify_all();
4750
}
48-
m_cv.notify_all();
4951
m_state.store(State::SAFE_TO_DESTRUCT, std::memory_order_release);
5052
}
5153
void AsyncTask::run() noexcept{
54+
{
5255
#ifdef PA_SANITIZE_AsyncTask
53-
auto scope = m_sanitizer.check_scope();
56+
auto scope = m_sanitizer.check_scope();
5457
#endif
55-
try{
56-
m_task();
57-
}catch (...){
58-
std::lock_guard<std::mutex> lg(m_lock);
59-
m_exception = std::current_exception();
58+
try{
59+
m_task();
60+
}catch (...){
61+
std::lock_guard<std::mutex> lg(m_lock);
62+
m_exception = std::current_exception();
63+
}
6064
}
6165
report_cancelled();
6266
}

0 commit comments

Comments
 (0)