Skip to content

Commit 32264c8

Browse files
committed
rocket/once_flag: Avoid try..catch..rethrow
1 parent be5dd1a commit 32264c8

File tree

1 file changed

+10
-8
lines changed

1 file changed

+10
-8
lines changed

rocket/once_flag.hpp

+10-8
Original file line numberDiff line numberDiff line change
@@ -37,14 +37,16 @@ class once_flag
3737
|| (::abi::__cxa_guard_acquire(this->m_guard) == 0))
3838
return;
3939

40-
try {
41-
forward<funcT>(func) (forward<paramsT>(params)...);
42-
::abi::__cxa_guard_release(this->m_guard);
43-
}
44-
catch(...) {
45-
::abi::__cxa_guard_abort(this->m_guard);
46-
throw;
47-
}
40+
struct Sentry
41+
{
42+
decltype(::abi::__cxa_guard_abort)* dtor;
43+
::abi::__guard* guard;
44+
~Sentry() { (* this->dtor) (this->guard); }
45+
};
46+
47+
Sentry sentry = { ::abi::__cxa_guard_abort, this->m_guard };
48+
forward<funcT>(func) (forward<paramsT>(params)...);
49+
sentry.dtor = ::abi::__cxa_guard_release;
4850
}
4951
};
5052

0 commit comments

Comments
 (0)