Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove #include <condition_variable> from Log.hpp [12720] #2281

Merged
merged 2 commits into from
Dec 17, 2021
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
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