Skip to content

Commit

Permalink
⚡ (LogKit): Process fifo by chuncks of 64 bytes
Browse files Browse the repository at this point in the history
  • Loading branch information
ladislas committed Nov 14, 2022
1 parent d14d36b commit aa71c66
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 8 deletions.
8 changes: 4 additions & 4 deletions libs/LogKit/include/LogKit.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,8 @@ namespace buffer {
inline auto message = std::array<char, 256> {};
inline auto output = std::array<char, 512> {};

inline auto fifo = CircularQueue<char, 4096> {};
inline auto fifo = CircularQueue<char, 4096> {};
static auto process_buffer = std::array<char, 64> {};

}; // namespace buffer

Expand Down Expand Up @@ -104,9 +105,8 @@ namespace internal {
inline void process_fifo()
{
while (!buffer::fifo.empty()) {
auto c = char {};
buffer::fifo.pop(c);
internal::filehandle->write(&c, 1);
auto length = buffer::fifo.pop(buffer::process_buffer.data(), std::size(buffer::process_buffer));
internal::filehandle->write(buffer::process_buffer.data(), length);
}
}

Expand Down
8 changes: 4 additions & 4 deletions libs/LogKit/tests/LogKit_test_fifo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,21 +50,21 @@ TEST_F(LogKitFifoTest, processEmpty)

TEST_F(LogKitFifoTest, processNotEmpty)
{
EXPECT_CALL(mockfh, write).Times(128);
EXPECT_CALL(mockfh, write).Times(128 / std::size(logger::buffer::process_buffer));

for (auto i = 0; i < 128; ++i) {
logger::buffer::fifo.push(i);
logger::buffer::fifo.push(static_cast<char>(i));
}

logger::process_fifo();
}

TEST_F(LogKitFifoTest, processFull)
{
EXPECT_CALL(mockfh, write).Times(4096);
EXPECT_CALL(mockfh, write).Times(4096 / std::size(logger::buffer::process_buffer));

for (auto i = 0; i < 4096; ++i) {
logger::buffer::fifo.push(i);
logger::buffer::fifo.push(static_cast<char>(i));
}

logger::process_fifo();
Expand Down

0 comments on commit aa71c66

Please sign in to comment.