Permalink
Browse files

force to terminate and detach worker thread in destructor, resolve #5

  • Loading branch information...
flier committed Jul 2, 2017
1 parent 34e4b95 commit aba0ffe49e96d291436468f39d83fafb6ace1ce3
Showing with 11 additions and 6 deletions.
  1. +3 −3 src/Collector.cpp
  2. +7 −2 src/Collector.h
  3. +1 −1 src/KafkaCollector.h
View
@@ -191,7 +191,7 @@ bool BaseCollector::flush(std::chrono::milliseconds timeout_ms)
if (m_terminated)
{
VLOG(3) << "shutdow " << name() << " collector and wait " << timeout_ms.count() << " ms";
VLOG(3) << "shutdown " << name() << " collector and wait " << timeout_ms.count() << " ms";
}
else if (m_spans.empty())
{
@@ -207,7 +207,7 @@ bool BaseCollector::flush(std::chrono::milliseconds timeout_ms)
void BaseCollector::shutdown(std::chrono::milliseconds timeout_ms)
{
m_terminated = true;
if (m_terminated.exchange(true)) return;
if (!flush(timeout_ms) && m_worker.joinable())
{
@@ -289,4 +289,4 @@ void BaseCollector::send_spans(void)
}
}
} // namespace zipkin
} // namespace zipkin
View
@@ -189,7 +189,12 @@ class BaseCollector : public Collector
{
}
virtual ~BaseCollector() = default;
virtual ~BaseCollector()
{
if (!m_terminated.exchange(true)) {
m_worker.detach();
}
}
virtual void send_message(const uint8_t *msg, size_t size) = 0;
@@ -203,4 +208,4 @@ class BaseCollector : public Collector
virtual void shutdown(std::chrono::milliseconds timeout_ms) override;
};
} // namespace zipkin
} // namespace zipkin
View
@@ -65,7 +65,7 @@ class KafkaCollector : public Collector
virtual void shutdown(std::chrono::milliseconds timeout_ms) override
{
flush(std::chrono::milliseconds(500));
flush(timeout_ms);
}
};

0 comments on commit aba0ffe

Please sign in to comment.