Skip to content

Commit

Permalink
Few tweaks from self review
Browse files Browse the repository at this point in the history
  • Loading branch information
cjappl committed Dec 28, 2024
1 parent 464d622 commit 4a03c09
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 17 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ Slides:
- Ability to log messages of any type and size from the real-time thread
- Statically allocated memory at compile time, no allocations in the real-time thread
- Support for printf-style format specifiers (using [a version of the printf family](https://github.com/nothings/stb/blob/master/stb_sprintf.h) that doesn't hit the `localeconv` lock) OR support for modern libfmt formatting.
- Efficient thread-safe logging using a [lock free queue](https://github.com/hogliux/farbot)
- Efficient thread-safe logging using a [lock free queue](https://github.com/hogliux/farbot).

## Requirements

Expand Down Expand Up @@ -102,7 +102,7 @@ static auto PrintMessage = [](const ExampleLogData& data, size_t sequenceNumber,
vsnprintf(buffer.data(), buffer.size(), fstring, args);
va_end(args);
printf("{%lu} [%s] (%s): %s\n",
printf("{%lu} [%s] (%s): %s\n",
sequenceNumber,
rtlog::test::to_string(data.level),
rtlog::test::to_string(data.region),
Expand Down
19 changes: 5 additions & 14 deletions include/rtlog/rtlog.h
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,7 @@ class Logger {
using InternalLogData = detail::BasicLogData<LogData, MaxMessageLength>;
using InternalQType = QType<InternalLogData>;

static_assert(MaxNumMessages > 0);
static_assert((MaxNumMessages & (MaxNumMessages - 1)) == 0,
"MaxNumMessages must be a power of 2");
static_assert(
Expand Down Expand Up @@ -257,13 +258,8 @@ class Logger {
// data loss
const bool dataWasEnqueued = mQueue.try_enqueue(std::move(dataToQueue));

constexpr bool isMultiRealtimeWriterQueueType =
std::is_same_v<InternalQType,
MultiRealtimeWriterQueueType<InternalLogData>>;
if constexpr (!isMultiRealtimeWriterQueueType) {
if (!dataWasEnqueued)
retVal = Status::Error_QueueFull;
}
if (!dataWasEnqueued)
retVal = Status::Error_QueueFull;

return retVal;
}
Expand Down Expand Up @@ -359,13 +355,8 @@ class Logger {
// data loss
const bool dataWasEnqueued = mQueue.try_enqueue(std::move(dataToQueue));

constexpr bool isMultiRealtimeWriterQueueType =
std::is_same_v<InternalQType,
MultiRealtimeWriterQueueType<InternalLogData>>;
if constexpr (!isMultiRealtimeWriterQueueType) {
if (!dataWasEnqueued)
retVal = Status::Error_QueueFull;
}
if (!dataWasEnqueued)
retVal = Status::Error_QueueFull;

return retVal;
};
Expand Down
2 changes: 1 addition & 1 deletion test/test_rtlog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ TYPED_TEST(TruncatedRtLogTest, ErrorsReturnedFromLog) {
va_end(args);

EXPECT_STREQ(buffer.data(), "Hello, 12");
EXPECT_EQ(strlen(buffer.data()), maxMessageLength - 1);
EXPECT_EQ(strlen(buffer.data()), this->maxMessageLength - 1);
};
EXPECT_EQ(logger.PrintAndClearLogQueue(InspectLogMessage), 2);
}
Expand Down

0 comments on commit 4a03c09

Please sign in to comment.