Skip to content

Commit

Permalink
Prevent multiple usage of FrontendOptions
Browse files Browse the repository at this point in the history
  • Loading branch information
odygrd authored Jun 15, 2024
1 parent f15abe8 commit 17df58b
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
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

0 comments on commit 17df58b

Please sign in to comment.