SinkImpl: Keep enabled count rather than just boolean.

This allows e.g. multiple HTTP streams to individually call Enable() and
Disable().
This commit is contained in:
Peter Johnson
2016-10-13 00:13:18 -07:00
parent ee24a6f4fc
commit 7f88bd15d1
2 changed files with 8 additions and 13 deletions

View File

@@ -15,19 +15,18 @@ SinkImpl::SinkImpl(llvm::StringRef name) : m_name{name} {}
SinkImpl::~SinkImpl() {
if (m_source) {
if (m_enabled) m_source->DisableSink();
if (m_enabledCount > 0) m_source->DisableSink();
m_source->RemoveSink();
}
}
void SinkImpl::SetSource(std::shared_ptr<SourceImpl> source) {
std::lock_guard<std::mutex> lock(m_mutex);
bool was_enabled = m_enabled;
if (m_source) {
if (m_enabled) m_source->DisableSink();
if (m_enabledCount > 0) m_source->DisableSink();
m_source->RemoveSink();
}
m_source = source;
m_source->AddSink();
if (was_enabled) m_source->EnableSink();
if (m_enabledCount > 0) m_source->EnableSink();
}