Source: Keep track of how many sinks are connected and enabled.

This commit is contained in:
Peter Johnson
2016-09-08 23:52:23 -07:00
parent ddb97bfafb
commit ba241cd7f9
5 changed files with 83 additions and 9 deletions

View File

@@ -12,3 +12,22 @@
using namespace cs;
SinkImpl::SinkImpl(llvm::StringRef name) : m_name{name} {}
SinkImpl::~SinkImpl() {
if (m_source) {
if (m_enabled) 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();
m_source->RemoveSink();
}
m_source = source;
m_source->AddSink();
if (was_enabled) m_source->EnableSink();
}