Skip to content

Commit

Permalink
allow multiple instances ofthe loggers
Browse files Browse the repository at this point in the history
  • Loading branch information
facontidavide committed Jun 18, 2024
1 parent a574bea commit ced041b
Show file tree
Hide file tree
Showing 4 changed files with 2 additions and 24 deletions.
2 changes: 0 additions & 2 deletions include/behaviortree_cpp/loggers/bt_cout_logger.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,6 @@ namespace BT

class StdCoutLogger : public StatusChangeLogger
{
static std::atomic<bool> ref_count;

public:
StdCoutLogger(const BT::Tree& tree);
~StdCoutLogger() override;
Expand Down
2 changes: 0 additions & 2 deletions include/behaviortree_cpp/loggers/bt_minitrace_logger.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@ namespace BT
{
class MinitraceLogger : public StatusChangeLogger
{
static std::atomic<bool> ref_count;

public:
MinitraceLogger(const BT::Tree& tree, const char* filename_json);

Expand Down
14 changes: 2 additions & 12 deletions src/loggers/bt_cout_logger.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,11 @@

namespace BT
{
std::atomic<bool> StdCoutLogger::ref_count(false);

StdCoutLogger::StdCoutLogger(const BT::Tree& tree) : StatusChangeLogger(tree.rootNode())
{
bool expected = false;
if(!ref_count.compare_exchange_strong(expected, true))
{
throw LogicError("Only one instance of StdCoutLogger shall be created");
}
}
{}
StdCoutLogger::~StdCoutLogger()
{
ref_count.store(false);
}
{}

void StdCoutLogger::callback(Duration timestamp, const TreeNode& node,
NodeStatus prev_status, NodeStatus status)
Expand All @@ -35,7 +26,6 @@ void StdCoutLogger::callback(Duration timestamp, const TreeNode& node,
void StdCoutLogger::flush()
{
std::cout << std::flush;
ref_count = false;
}

} // namespace BT
8 changes: 0 additions & 8 deletions src/loggers/bt_minitrace_logger.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,10 @@

namespace BT
{
std::atomic<bool> MinitraceLogger::ref_count(false);

MinitraceLogger::MinitraceLogger(const Tree& tree, const char* filename_json)
: StatusChangeLogger(tree.rootNode())
{
bool expected = false;
if(!ref_count.compare_exchange_strong(expected, true))
{
throw LogicError("Only one instance of MinitraceLogger shall be created");
}

mtr_register_sigint_handler();
mtr_init(filename_json);
this->enableTransitionToIdle(true);
Expand All @@ -26,7 +19,6 @@ MinitraceLogger::~MinitraceLogger()
{
mtr_flush();
mtr_shutdown();
ref_count = false;
}

const char* toConstStr(NodeType type)
Expand Down

0 comments on commit ced041b

Please sign in to comment.