userver: userver/utils/impl/static_registration.hpp Source File
Loading...
Searching...
No Matches
static_registration.hpp
1#pragma once
2
3#include <atomic>
4#include <string_view>
5
6#include <userver/utils/assert.hpp>
7
8USERVER_NAMESPACE_BEGIN
9
10namespace utils::impl {
11
12extern std::atomic<bool> is_static_registration_finished;
13
14void AssertStaticRegistrationAllowed(std::string_view operation_name);
15
16// Defined inline to optimize away in Release builds
17inline void AssertStaticRegistrationFinished() noexcept {
18 UASSERT_MSG(is_static_registration_finished,
19 "This operation is only allowed after static initialization "
20 "completes, see stacktrace");
21}
22
23// Called in TaskProcessor constructor, before the creation of first
24// TaskContext. Ideally should be called in the beginning of main(). As long as
25// AssertStaticRegistrationFinished does not fire, it's placed in enough places.
26void FinishStaticRegistration() noexcept;
27
28} // namespace utils::impl
29
30USERVER_NAMESPACE_END