Skip to content
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
4 changes: 3 additions & 1 deletion docs/TaskExecutor.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,9 @@ lifetime guarantees that logger integrations rely on.
* Uses `m_active_tasks` to count in-flight work. If the counter reaches the
limit, producers wait. The non-MPSC build waits on
`m_queue_condition`. The MPSC build parks on `m_cv` with short sleeps while
the worker drains tasks. This policy avoids loss at the expense of
the worker drains tasks. The sleep interval defaults to
`LOGIT_TASK_EXECUTOR_BLOCK_WAIT_USEC` microseconds (200 by default) and can
be overridden at compile time. This policy avoids loss at the expense of
producer-side backpressure.
* `DropNewest`
* Non-MPSC: the incoming task is discarded when the deque is full.
Expand Down
1 change: 1 addition & 0 deletions include/logit_cpp/logit/Logger.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
/// \file Logger.hpp
/// \brief Defines the Logger class for managing multiple loggers and formatters.

#include "config.hpp"
#include "loggers/ILogger.hpp"
#include "formatter.hpp"
#include "detail/TaskExecutor.hpp"
Expand Down
9 changes: 9 additions & 0 deletions include/logit_cpp/logit/config.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,15 @@
#define LOGIT_DEFAULT_COLOR logit::TextColor::LightGray
#endif

/// \brief Defines the sleep duration (in microseconds) used by TaskExecutor when blocking producers.
///
/// When `QueuePolicy::Block` is active, the TaskExecutor periodically waits for
/// capacity to become available. Override this value to tweak the polling
/// cadence in builds where the default wait is not appropriate.
#ifndef LOGIT_TASK_EXECUTOR_BLOCK_WAIT_USEC
#define LOGIT_TASK_EXECUTOR_BLOCK_WAIT_USEC 200
#endif

/// \name Log Level Colors
/// Default colors for each log level.
/// \{
Expand Down
4 changes: 2 additions & 2 deletions include/logit_cpp/logit/detail/TaskExecutor.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,7 @@ namespace logit { namespace detail {
m_active_tasks.load(std::memory_order_relaxed) >= m_max_queue_size)
{
std::unique_lock<std::mutex> lk(m_cv_mutex);
m_cv.wait_for(lk, std::chrono::microseconds(200));
m_cv.wait_for(lk, std::chrono::microseconds(LOGIT_TASK_EXECUTOR_BLOCK_WAIT_USEC));
continue;
}

Expand All @@ -266,7 +266,7 @@ namespace logit { namespace detail {

case QueuePolicy::Block: {
std::unique_lock<std::mutex> lk(m_cv_mutex);
m_cv.wait_for(lk, std::chrono::microseconds(200));
m_cv.wait_for(lk, std::chrono::microseconds(LOGIT_TASK_EXECUTOR_BLOCK_WAIT_USEC));
break;
}
}
Expand Down
Loading