[DEV] add mutex

This commit is contained in:
Edouard DUPIN 2015-01-28 23:01:12 +01:00
parent 7be8623614
commit 948ad6b726
2 changed files with 19 additions and 11 deletions

View File

@ -270,9 +270,11 @@ std::chrono::system_clock::time_point airtio::Interface::getCurrentTime() const
void airtio::Interface::systemNewInputData(std::chrono::system_clock::time_point _time, void* _data, size_t _nbChunk) {
std::unique_lock<std::mutex> lock(m_mutex);
m_process->push(_time, _data, _nbChunk);
}
void airtio::Interface::systemNeedOutputData(std::chrono::system_clock::time_point _time, void*& _data, size_t& _nbChunk, size_t _chunkSize) {
std::unique_lock<std::mutex> lock(m_mutex);
m_process->pull(_time, _data, _nbChunk);//, _chunkSize);
}

View File

@ -203,7 +203,7 @@ airtio::io::Node::Node(const std::string& _streamName, bool _isInput) :
airtio::io::Node::~Node() {
std::unique_lock<std::mutex> lock(m_mutex);
AIRTIO_INFO("-----------------------------------------------------------------");
AIRTIO_INFO("-- DESTRO NODE --");
AIRTIO_INFO("-- DESTROY NODE --");
AIRTIO_INFO("-----------------------------------------------------------------");
AIRTIO_INFO("close input stream");
if (m_adac.isStreamOpen() ) {
@ -230,24 +230,30 @@ void airtio::io::Node::stop() {
}
void airtio::io::Node::interfaceAdd(const std::shared_ptr<airtio::Interface>& _interface) {
for (size_t iii=0; iii< m_list.size(); ++iii) {
if (_interface == m_list[iii]) {
return;
{
std::unique_lock<std::mutex> lock(m_mutex);
for (size_t iii=0; iii< m_list.size(); ++iii) {
if (_interface == m_list[iii]) {
return;
}
}
AIRTIO_INFO("ADD interface for stream : '" << m_streamName << "' mode=" << (m_isInput?"input":"output") );
m_list.push_back(_interface);
}
AIRTIO_INFO("ADD interface for stream : '" << m_streamName << "' mode=" << (m_isInput?"input":"output") );
m_list.push_back(_interface);
if (m_list.size() == 1) {
start();
}
}
void airtio::io::Node::interfaceRemove(const std::shared_ptr<airtio::Interface>& _interface) {
for (size_t iii=0; iii< m_list.size(); ++iii) {
if (_interface == m_list[iii]) {
m_list.erase(m_list.begin()+iii);
AIRTIO_INFO("RM interface for stream : '" << m_streamName << "' mode=" << (m_isInput?"input":"output") );
break;
{
std::unique_lock<std::mutex> lock(m_mutex);
for (size_t iii=0; iii< m_list.size(); ++iii) {
if (_interface == m_list[iii]) {
m_list.erase(m_list.begin()+iii);
AIRTIO_INFO("RM interface for stream : '" << m_streamName << "' mode=" << (m_isInput?"input":"output") );
break;
}
}
}
if (m_list.size() == 0) {