This repository has been archived on 2024-07-30. You can view files and clone it, but cannot push or open issues or pull requests.
XbeeMav/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_Pack(const _T& new_data)
{
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_;
};
}
}