60 lines
1.5 KiB
C++
60 lines
1.5 KiB
C++
// /*
|
|
// * This Source Code Form is subject to the terms of the Mozilla Public
|
|
// * License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
// * file, You can obtain one at https://mozilla.org/MPL/2.0/.
|
|
// */
|
|
|
|
// /**
|
|
// * @file BasicMessageQueue.cpp
|
|
// * @brief class which encapsulates queue
|
|
// * @author Christina Sander <christina.sander@hsu-hh.de>
|
|
// * @date 25.06.2020
|
|
// * @copyright MPLv2
|
|
// */
|
|
// #include <WHISPER/threadSafeQueue.hpp>
|
|
// #include <iostream>
|
|
// #include <string>
|
|
|
|
// template<class T>
|
|
// WHISPER::threadSafeQueue<T> threadSafeQueue(){
|
|
|
|
// }
|
|
|
|
|
|
|
|
// // appends the given message to the message queue
|
|
// template<class T>
|
|
// void WHISPER::threadSafeQueue< T>::addElement(std::unique_ptr<T> elem)
|
|
// {
|
|
// std::unique_lock<std::mutex> lk(mx);
|
|
// q.push( std::move(elem) );
|
|
// lk.unlock();
|
|
// condVar.notify_one();
|
|
// }
|
|
|
|
// // gets a message from the queue
|
|
// template<class T>
|
|
// std::unique_ptr<T> WHISPER::threadSafeQueue<T>::getElement()
|
|
// {
|
|
// std::unique_lock<std::mutex> lk(mx);
|
|
// if( 0 == q.size() )
|
|
// {
|
|
// lk.unlock();
|
|
// throw std::length_error("Empty Queue\n");
|
|
// }
|
|
// std::unique_ptr<std::string> elem = std::move( q.front() );
|
|
// q.pop();
|
|
// lk.unlock();
|
|
// return std::move(elem);
|
|
// }
|
|
|
|
|
|
// //returns the size of the message queue
|
|
// template<class T>
|
|
// unsigned int WHISPER::threadSafeQueue<T>::size()
|
|
// {
|
|
// std::unique_lock<std::mutex> lk(mx);
|
|
// unsigned int size = q.size();
|
|
// lk.unlock();
|
|
// return size;
|
|
// }
|