Skip to content

Commit

Permalink
Remove #include <condition_variable> from Log.hpp (#2281)
Browse files Browse the repository at this point in the history
* Refs #12161. Avoid including condition_variable to user

Signed-off-by: Ricardo González <ricardo@richiware.dev>

* Refs #12720. Fix test compilation error

Signed-off-by: Ricardo González Moreno <ricardo@richiware.dev>
  • Loading branch information
richiware authored Dec 17, 2021
1 parent 7f4a103 commit 7e68d98
Show file tree
Hide file tree
Showing 5 changed files with 49 additions and 48 deletions.
31 changes: 0 additions & 31 deletions include/fastdds/dds/log/Log.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
#ifndef _FASTDDS_DDS_LOG_LOG_HPP_
#define _FASTDDS_DDS_LOG_LOG_HPP_

#include <fastrtps/utils/DBQueue.h>
#include <fastrtps/fastrtps_dll.h>
#include <thread>
#include <sstream>
Expand Down Expand Up @@ -154,36 +153,6 @@ class Log

private:

struct Resources
{
fastrtps::DBQueue<Entry> logs;
std::vector<std::unique_ptr<LogConsumer>> consumers;
std::unique_ptr<std::thread> logging_thread;

// Condition variable segment.
std::condition_variable cv;
std::mutex cv_mutex;
bool logging;
bool work;
int current_loop;

// Context configuration.
std::mutex config_mutex;
bool filenames;
bool functions;
std::unique_ptr<std::regex> category_filter;
std::unique_ptr<std::regex> filename_filter;
std::unique_ptr<std::regex> error_string_filter;

std::atomic<Log::Kind> verbosity;

Resources();

~Resources();
};

static struct Resources resources_;

// Applies transformations to the entries compliant with the options selected (such as
// erasure of certain context information, or filtering by category. Returns false
// if the log entry is blacklisted.
Expand Down
2 changes: 2 additions & 0 deletions include/fastdds/rtps/writer/LocatorSelectorSender.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
#include <fastdds/rtps/messages/RTPSMessageSenderInterface.hpp>
#include <fastrtps/utils/collections/ResourceLimitedVector.hpp>

#include <mutex>

namespace eprosima {
namespace fastrtps {
namespace rtps {
Expand Down
60 changes: 44 additions & 16 deletions src/cpp/fastdds/log/Log.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
#include <iomanip>
#include <mutex>

#include <fastrtps/utils/DBQueue.h>

#include <fastdds/dds/log/Log.hpp>
#include <fastdds/dds/log/OStreamConsumer.hpp>
#include <fastdds/dds/log/StdoutConsumer.hpp>
Expand All @@ -28,27 +30,53 @@ namespace eprosima {
namespace fastdds {
namespace dds {

struct Log::Resources Log::resources_;

Log::Resources::Resources()
: logging(false)
, work(false)
, current_loop(0)
, filenames(false)
, functions(true)
, verbosity(Log::Error)
struct Resources
{
fastrtps::DBQueue<Log::Entry> logs;
std::vector<std::unique_ptr<LogConsumer>> consumers;
std::unique_ptr<std::thread> logging_thread;

// Condition variable segment.
std::condition_variable cv;
std::mutex cv_mutex;
bool logging;
bool work;
int current_loop;

// Context configuration.
std::mutex config_mutex;
bool filenames;
bool functions;
std::unique_ptr<std::regex> category_filter;
std::unique_ptr<std::regex> filename_filter;
std::unique_ptr<std::regex> error_string_filter;

std::atomic<Log::Kind> verbosity;

Resources()
: logging(false)
, work(false)
, current_loop(0)
, filenames(false)
, functions(true)
, verbosity(Log::Error)
{
#if STDOUTERR_LOG_CONSUMER
resources_.consumers.emplace_back(new StdoutErrConsumer);
consumers.emplace_back(new StdoutErrConsumer);
#else
resources_.consumers.emplace_back(new StdoutConsumer);
consumers.emplace_back(new StdoutConsumer);
#endif // STDOUTERR_LOG_CONSUMER
}
}

~Resources()
{
Log::KillThread();
}

};

static struct Resources resources_;

Log::Resources::~Resources()
{
Log::KillThread();
}

void Log::RegisterConsumer(
std::unique_ptr<LogConsumer>&& consumer)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@
#include <fastrtps/rtps/attributes/HistoryAttributes.h>
#include <fastrtps/utils/TimedMutex.hpp>

#include <mutex>

#include <gmock/gmock.h>

namespace eprosima {
Expand Down
2 changes: 1 addition & 1 deletion test/unittest/logging/mock/MockConsumer.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
#include <thread>
#include <mutex>
#include <vector>
#include <condition_variable>

namespace eprosima {
namespace fastdds {
Expand Down Expand Up @@ -86,4 +87,3 @@ class MockConsumer : public StdoutConsumer
} // namespace eprosima

#endif // ifndef MOCK_LOG_CONSUMER_H

0 comments on commit 7e68d98

Please sign in to comment.