services-ros1-xbee_mav/include/MultithreadingDeque.hpp

74 lines
1.4 KiB
C++
Raw Normal View History

2017-01-10 13:14:41 -04:00
/* MultithreadingDeque.hpp -- Safe Multithreading Deque class -- */
/* ------------------------------------------------------------------------- */
/* September 20, 2016 -- @Copyright Aymen Soussia. All rights reserved. */
/* (aymen.soussia@gmail.com) */
#pragma once
#include<deque>
#include<mutex>
namespace Mist
{
namespace Xbee
{
//*****************************************************************************
template<typename _T>
class MultithreadingDeque
{
public:
//****************************************************************************
MultithreadingDeque()
{
}
//****************************************************************************
~MultithreadingDeque()
{
}
//****************************************************************************
void Push_Back(const _T& new_data)
2017-01-10 13:14:41 -04:00
{
std::lock_guard<std::mutex> guard(mutex_);
deque_.push_back(new_data);
}
//****************************************************************************
_T Pop_Front()
{
std::lock_guard<std::mutex> guard(mutex_);
_T value = deque_.front();
deque_.pop_front();
return value;
}
//****************************************************************************
unsigned int Get_Size()
{
std::lock_guard<std::mutex> guard(mutex_);
return deque_.size();
}
private:
std::mutex mutex_;
std::deque<_T> deque_;
};
}
}