未验证 提交 25cb9064 编写于 作者: Y Yang Yang(Tony) 提交者: GitHub

Fix call once logic (#7839)

* fix call once logic

* clean up

* further clean up
上级 d380ad06
...@@ -29,20 +29,25 @@ namespace platform { ...@@ -29,20 +29,25 @@ namespace platform {
*/ */
template <typename Callable, typename... Args> template <typename Callable, typename... Args>
inline void call_once(std::once_flag& flag, Callable&& f, Args&&... args) { inline void call_once(std::once_flag& flag, Callable&& f, Args&&... args) {
bool good = false; bool good = true;
std::exception ex; std::exception ex;
try {
std::call_once(flag, std::call_once(flag,
[&](Args&&... args) { [&](Args&&... args) {
try { try {
f(args...); f(args...);
good = true;
} catch (const std::exception& e) { } catch (const std::exception& e) {
ex = e; ex = e;
good = false;
} catch (...) { } catch (...) {
ex = std::runtime_error("excption caught in call_once"); ex = std::runtime_error("excption caught in call_once");
good = false;
} }
}, },
args...); args...);
} catch (std::system_error& x) {
throw std::runtime_error("call once failed");
}
if (!good) { if (!good) {
throw std::exception(ex); throw std::exception(ex);
} }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册