#pragma once

#include <queue>
#include <vector>
#include "../../Utils/CriticalSection.h"

template<class T, class Comp = std::less<T> >
class ConcurrentPriorityQueue
{
  std::priority_queue<T, std::vector<T>, Comp> m_queue;
  CriticalSection m_mutex;
public:
  ConcurrentPriorityQueue(const Comp &cmp = Comp()) : m_queue(cmp) {}

  void push(const T &value)
  {
    CriticalSection::scoped_lock lock(m_mutex);
    m_queue.push(value);
  }

  bool try_pop(T & value)
  {
    CriticalSection::scoped_lock lock(m_mutex);
    if(m_queue.empty())
      return false;

    value = m_queue.top();
    m_queue.pop();
    return true;
  }
};