Commit 31944307 authored by Michael Ott's avatar Michael Ott
Browse files

Remove pusherpqueue.h as it is not used anymore

parent f2d3c740
......@@ -56,7 +56,7 @@ else
OPENSSL_TARGET = $(if $(findstring $(shell uname),Darwin),"darwin64-x86_64-cc","linux-x86_64")
endif
PUBHEADERS = pusherpqueue.h dcdbdaemon.h
PUBHEADERS = dcdbdaemon.h
FULL_CC = $(shell which $(CC))
FULL_CXX = $(shell which $(CXX))
......
//================================================================================
// Name : pusherpqeue.h
// Author : Axel Auweter
// Copyright : Leibniz Supercomputing Centre
// Description : Template class for priority queues used by various DCDB pushers
//================================================================================
//================================================================================
// This file is part of DCDB (DataCenter DataBase)
// Copyright (C) 2011-2016 Leibniz Supercomputing Centre
//
// This library is free software; you can redistribute it and/or
// modify it under the terms of the GNU Lesser General Public
// License as published by the Free Software Foundation; either
// version 2.1 of the License, or (at your option) any later version.
//
// This library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
// Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public
// License along with this library; if not, write to the Free Software
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
//================================================================================
#include <list>
#include <boost/date_time/posix_time/posix_time.hpp>
#include <boost/thread/condition_variable.hpp>
#include <boost/thread/mutex.hpp>
#include <boost/thread/lock_types.hpp>
#ifndef PUSHERPQUEUE_H_
#define PUSHERPQUEUE_H_
class ListSemaphore {
private:
unsigned int count_;
boost::mutex countMtx_;
boost::condition_variable cond_;
public:
ListSemaphore(unsigned int initialCount) {
count_ = initialCount;
}
void post() {
boost::unique_lock<boost::mutex> lock(countMtx_);
count_++;
cond_.notify_one();
}
void wait() {
boost::unique_lock<boost::mutex> lock(countMtx_);
while (count_ == 0) {
cond_.wait(lock);
}
count_--;
}
};
template <class T>
class PusherPQueue
{
protected:
struct pListElement_ {
T elem_;
boost::posix_time::ptime dueTime_;
};
ListSemaphore pListSem_;
std::list<struct pListElement_> pList_;
bool abort_;
public:
void insert(T element, boost::posix_time::ptime dueTime);
void sleepUntilNext();
T popNext();
bool empty();
void abort();
unsigned int size();
PusherPQueue();
virtual ~PusherPQueue();
};
template <class T>
void PusherPQueue<T>::insert(T element, boost::posix_time::ptime dueTime)
{
/*
* Insert the element into the priority queue and increase
* the queue length semaphore.
*/
struct pListElement_ e;
e.elem_ = element;
e.dueTime_ = dueTime;
typename std::list<struct pListElement_>::iterator iter;
for (iter = pList_.begin(); iter != pList_.end(); iter++) {
if ((*iter).dueTime_ > dueTime) {
pList_.insert(iter, e);
pListSem_.post();
return;
}
}
/*
* In case the list was empty or the due time of
* the element is after the last element in the
* list, we'll end up here.
*/
pList_.push_back(e);
pListSem_.post();
}
template <class T>
void PusherPQueue<T>::sleepUntilNext()
{
/*
* Block if there is no element in the list. As the
* element is not being removed by this function,
* post the semaphore right after.
*/
pListSem_.wait();
if(abort_)
return;
pListSem_.post();
/*
* Sleep until the first element in the queue
* is due.
*/
pListElement_ first;
first = pList_.front();
boost::posix_time::ptime now = boost::posix_time::microsec_clock::universal_time();
boost::posix_time::time_duration diff = first.dueTime_ - now;
if (diff.is_negative())
return;
usleep(diff.total_microseconds());
}
template <class T>
T PusherPQueue<T>::popNext()
{
/*
* Pop the first element from the priority queue.
*/
pListSem_.wait();
T ret = pList_.front().elem_;
pList_.pop_front();
return ret;
}
template <class T>
bool PusherPQueue<T>::empty()
{
/*
* Return true if the list is empty.
*/
return pList_.empty();
}
template <class T>
void PusherPQueue<T>::abort()
{
/*
* Break out of a blocked sleepUntilNext()...
*/
abort_ = true;
pListSem_.post();
}
template <class T>
unsigned int PusherPQueue<T>::size()
{
/*
* Return the size of the list
*/
return pList_.size();
}
template <class T>
PusherPQueue<T>::PusherPQueue() : pListSem_(0), abort_(false)
{
/*
* Nothing to be done here...
*/
}
template <class T>
PusherPQueue<T>::~PusherPQueue()
{
/*
* Nothing to be done here...
*/
}
#endif /* PUSHERPQUEUE_H_ */
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment