Skip to content

Commit

Permalink
Safeguard against any potential static init order issues, mentioned in
Browse files Browse the repository at this point in the history
  • Loading branch information
jeremy-rifkin committed Dec 22, 2024
1 parent 3bf1bc6 commit 3849ce1
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions src/assert.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -448,16 +448,19 @@ namespace libassert {
}
}

static std::atomic failure_handler = default_failure_handler;
static auto& get_failure_handler() {
static std::atomic handler = default_failure_handler;
return handler;
}

LIBASSERT_ATTR_COLD LIBASSERT_EXPORT
void set_failure_handler(void (*handler)(const assertion_info&)) {
failure_handler = handler;
get_failure_handler() = handler;
}

namespace detail {
LIBASSERT_ATTR_COLD LIBASSERT_EXPORT void fail(const assertion_info& info) {
failure_handler.load()(info);
get_failure_handler().load()(info);
}
}

Expand Down

0 comments on commit 3849ce1

Please sign in to comment.