Allow Sink.SetSource() to be given an empty source.

In Java, allow source to be null (pointers are not used in C++, so
this isn't necessary).
This commit is contained in:
Peter Johnson
2016-12-28 00:47:26 -08:00
parent b91ab0b44f
commit 23135d7a5a
4 changed files with 21 additions and 10 deletions

View File

@@ -67,13 +67,16 @@ void SinkImpl::SetEnabled(bool enabled) {
void SinkImpl::SetSource(std::shared_ptr<SourceImpl> source) {
{
std::lock_guard<std::mutex> lock(m_mutex);
if (m_source == source) return;
if (m_source) {
if (m_enabledCount > 0) m_source->DisableSink();
m_source->RemoveSink();
}
m_source = source;
m_source->AddSink();
if (m_enabledCount > 0) m_source->EnableSink();
if (m_source) {
m_source->AddSink();
if (m_enabledCount > 0) m_source->EnableSink();
}
}
SetSourceImpl(source);
}