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

Remove inclusion of Windows.h in Logger.h #621

Merged
merged 5 commits into from
Oct 31, 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: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,7 @@ set(HEADER_FILES
include/quill/backend/RdtscClock.h
include/quill/backend/SignalHandler.h
include/quill/backend/StringFromTime.h
include/quill/backend/ThreadUtilities.h
include/quill/backend/TimestampFormatter.h
include/quill/backend/TransitEvent.h
include/quill/backend/TransitEventBuffer.h
Expand Down Expand Up @@ -207,7 +208,6 @@ set(HEADER_FILES
include/quill/core/SinkManager.h
include/quill/core/Spinlock.h
include/quill/core/ThreadContextManager.h
include/quill/core/ThreadUtilities.h
include/quill/core/TimeUtilities.h
include/quill/core/UnboundedSPSCQueue.h
include/quill/core/Utf8Conv.h
Expand Down
2 changes: 1 addition & 1 deletion include/quill/backend/BackendUtilities.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@

#include <windows.h>

#include "quill/core/ThreadUtilities.h"
#include "quill/backend/ThreadUtilities.h"
#elif defined(__APPLE__)
#include <mach/thread_act.h>
#include <mach/thread_policy.h>
Expand Down
5 changes: 4 additions & 1 deletion include/quill/backend/BackendWorker.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
#include "quill/backend/BacktraceStorage.h"
#include "quill/backend/PatternFormatter.h"
#include "quill/backend/RdtscClock.h"
#include "quill/backend/ThreadUtilities.h"
#include "quill/backend/TimestampFormatter.h"
#include "quill/backend/TransitEvent.h"
#include "quill/backend/TransitEventBuffer.h"
Expand All @@ -28,7 +29,6 @@
#include "quill/core/QuillError.h"
#include "quill/core/SinkManager.h"
#include "quill/core/ThreadContextManager.h"
#include "quill/core/ThreadUtilities.h"
#include "quill/core/TimeUtilities.h"
#include "quill/core/UnboundedSPSCQueue.h"
#include "quill/sinks/Sink.h"
Expand Down Expand Up @@ -319,6 +319,9 @@ class BackendWorker
// Cache this thread's id
_worker_thread_id.store(get_thread_id());

// Call get_thread_name() to ensure it is retained by the linker.
(void)get_thread_name();

// Double check or modify some backend options before we start
if (_options.transit_events_hard_limit == 0)
{
Expand Down
3 changes: 2 additions & 1 deletion include/quill/backend/SignalHandler.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,15 @@

#pragma once

#include "quill/backend/ThreadUtilities.h"

#include "quill/Logger.h"
#include "quill/core/Attributes.h"
#include "quill/core/LogLevel.h"
#include "quill/core/LoggerBase.h"
#include "quill/core/LoggerManager.h"
#include "quill/core/MacroMetadata.h"
#include "quill/core/QuillError.h"
#include "quill/core/ThreadUtilities.h"

#include <atomic>
#include <csignal>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ ReturnT callRunTimeDynamicLinkedFunction(std::string const& dll_name,
* a null string is retrieved into name.
* @return the thread name
*/
QUILL_NODISCARD inline std::string get_thread_name()
QUILL_NODISCARD QUILL_EXPORT QUILL_ATTRIBUTE_USED inline std::string get_thread_name()
{
#if defined(__CYGWIN__) || defined(__MINGW32__) || defined(__MINGW64__) || defined(QUILL_NO_THREAD_NAME_SUPPORT)
// Disabled on MINGW / Cygwin.
Expand Down Expand Up @@ -172,7 +172,7 @@ QUILL_NODISCARD inline std::string get_thread_name()
* Returns the os assigned ID of the thread
* @return the thread ID of the calling thread
*/
QUILL_NODISCARD inline uint32_t get_thread_id() noexcept
QUILL_NODISCARD QUILL_EXPORT QUILL_ATTRIBUTE_USED inline uint32_t get_thread_id() noexcept
{
#if defined(__CYGWIN__)
// get thread id on cygwin not supported
Expand Down
11 changes: 11 additions & 0 deletions include/quill/core/Attributes.h
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,17 @@
#endif
#endif

/**
* Used
*/
#ifndef QUILL_ATTRIBUTE_USED
#if QUILL_HAS_ATTRIBUTE(used) || defined(__GNUC__) || defined(__clang__)
#define QUILL_ATTRIBUTE_USED __attribute__((used))
#else
#define QUILL_ATTRIBUTE_USED
#endif
#endif

/**
* Likely
*/
Expand Down
5 changes: 4 additions & 1 deletion include/quill/core/ThreadContextManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
#include "quill/core/Common.h"
#include "quill/core/InlinedVector.h"
#include "quill/core/Spinlock.h"
#include "quill/core/ThreadUtilities.h"
#include "quill/core/UnboundedSPSCQueue.h"

#include <atomic>
Expand All @@ -33,6 +32,10 @@ namespace detail
class TransitEventBuffer;
class BackendWorker;

/** We forward declare these to avoid including ThreadUtilities.h **/
std::string get_thread_name();
uint32_t get_thread_id() noexcept;

class ThreadContext
{
private:
Expand Down
1 change: 1 addition & 0 deletions test/unit_tests/ThreadContextManagerTest.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#include "doctest/doctest.h"

#include "quill/backend/ThreadUtilities.h"
#include "quill/core/FrontendOptions.h"
#include "quill/core/ThreadContextManager.h"
#include <array>
Expand Down
Loading