// $Header: https://oberon.oapd.inaf.it/shins/trunk/shins/src/util/threadsafe_queue.cpp 3471 2020-09-21 14:18:40Z depa $

#include "threadsafe_queue.h"
#include <IProperty.hpp>

// Partial specialization
template <>
bool threadsafe_queue<IProperty>::try_wait_and_compare(const IProperty& _inValue, IProperty& _outValue)
{
  bool res = false;
  boost::chrono::duration<long, boost::ratio<1> > waitDuration(14);
  boost::unique_lock<boost::mutex> lock(m_mut);
  // m_dataCond.wait(lock, boost::bind(&threadsafe_queue::wait_predicate, this));
  m_dataCond.wait_for(lock, waitDuration);
  _outValue = boost::move(m_dataQueue.front());
  if (_inValue.compareProperty(_outValue))
    {
      m_dataQueue.pop();
      res = true;
    }
  else
    m_dataCond.notify_one();
  return res;
}
