Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Prevent multiple FrontendOptions #473

Merged
merged 3 commits into from
Jun 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,8 @@
- Fixed multiple definitions of `quill::detail::get_error_message` ([#469](https://github.com/odygrd/quill/issues/469))
- Fixed an issue causing a `SIGABRT` when creating directories with a symlink folder path using GCC versions 8 or
9 ([#468](https://github.com/odygrd/quill/issues/468))
- Added an assertion to prevent the use of custom `FrontendOptions` together with
default `FrontendOptions` ([#453](https://github.com/odygrd/quill/issues/453))

## v4.4.0

Expand Down
14 changes: 14 additions & 0 deletions quill/include/quill/core/ThreadContextManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -335,6 +335,20 @@ class ScopedThreadContext
ScopedThreadContext(QueueType queue_type, uint32_t spsc_queue_capacity, bool huge_pages_enabled)
: _thread_context(std::make_shared<ThreadContext>(queue_type, spsc_queue_capacity, huge_pages_enabled))
{
#ifndef NDEBUG
// Thread-local flag to track if an instance has been created for this thread.
// This ensures that get_local_thread_context() is not called with different template arguments
// when using custom FrontendOptions. Having multiple thread contexts in a single thread is fine
// and functional but goes against the design principle of maintaining a single thread context
// per thread.
thread_local bool thread_local_instance_created = false;

assert(!thread_local_instance_created &&
R"(ScopedThreadContext can only be instantiated once per thread. It appears you may be combining default FrontendOptions with custom FrontendOptions. Ensure only one set of FrontendOptions is used to maintain a single thread context per thread.)");

thread_local_instance_created = true;
#endif

ThreadContextManager::instance().register_thread_context(_thread_context);
}

Expand Down