Skip to content

Commit

Permalink
Fix tests with Log: wait for Log background thread initialization on …
Browse files Browse the repository at this point in the history
…the first queued entry [16948] (#3270)

* Fix test

Signed-off-by: Irene Bandera <[email protected]>

* Uncrustifiy

Signed-off-by: Irene Bandera <[email protected]>

---------

Signed-off-by: Irene Bandera <[email protected]>
  • Loading branch information
irenebm authored Jun 16, 2023
1 parent 7d25058 commit 5ffc8a4
Showing 1 changed file with 14 additions and 6 deletions.
20 changes: 14 additions & 6 deletions src/cpp/fastdds/log/Log.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -209,8 +209,14 @@ struct LogResources
{
std::unique_lock<std::mutex> guard(cv_mutex_);
work_ = true;
// pessimization
cv_.notify_all();
// wait till the thread is initialized
cv_.wait(guard, [&]
{
return current_loop_;
});
}
cv_.notify_all();
}

//! Stops the logging_ thread. It will re-launch on the next call to QueueLog.
Expand Down Expand Up @@ -269,14 +275,16 @@ struct LogResources
logs_.Swap();
while (!logs_.Empty())
{
std::unique_lock<std::mutex> configGuard(config_mutex_);

Log::Entry& entry = logs_.Front();
if (preprocess(entry))
{
for (auto& consumer : consumers_)
std::unique_lock<std::mutex> configGuard(config_mutex_);

if (preprocess(entry))
{
consumer->Consume(entry);
for (auto& consumer : consumers_)
{
consumer->Consume(entry);
}
}
}
// This Pop() is also a barrier for Log::Flush wait condition
Expand Down

0 comments on commit 5ffc8a4

Please sign in to comment.