/usr/include/osl/misc/pointerQueue.h is in libosl-dev 0.6.0-3.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 | /* queue.h
*/
#ifndef OSL_POINTERQUEUE_H
#define OSL_POINTERQUEUE_H
#include <deque>
#include <boost/thread/thread.hpp>
#include <boost/thread/condition.hpp>
namespace osl
{
namespace misc
{
template <class T>
class PointerQueue
{
typedef std::deque<boost::shared_ptr<T> > queue_t;
queue_t data;
typedef boost::mutex Mutex;
mutable Mutex mutex;
volatile bool finish;
boost::condition condition;
public:
PointerQueue() : finish(false)
{
}
~PointerQueue()
{
if (! finish)
quit();
}
size_t size() const
{
Mutex::scoped_lock lk(mutex);
return data.size();
}
void push_back(boost::shared_ptr<T>& ptr)
{
Mutex::scoped_lock lk(mutex);
data.push_back(boost::shared_ptr<T>());
data.back().swap(ptr);
condition.notify_one();
}
private:
boost::shared_ptr<T> pop_front_in_lock()
{
if (! data.empty())
{
boost::shared_ptr<T> result = data.front();
data.pop_front();
return result;
}
return boost::shared_ptr<T>();
}
public:
boost::shared_ptr<T> pop_front_non_block()
{
Mutex::scoped_lock lk(mutex);
return pop_front_in_lock();
}
boost::shared_ptr<T> pop_front()
{
while (! finish)
{
Mutex::scoped_lock lk(mutex);
boost::shared_ptr<T> result = pop_front_in_lock();
if (result.get() || finish)
return result;
condition.wait(lk);
}
return boost::shared_ptr<T>();
}
void quit(int seconds=0)
{
finish = true;
if (seconds > 0)
boost::this_thread::sleep(boost::posix_time::seconds(seconds));
Mutex::scoped_lock lk(mutex);
condition.notify_all();
}
};
}
}
#endif /* OSL_POINTERQUEUE_H */
// ;;; Local Variables:
// ;;; mode:c++
// ;;; c-basic-offset:2
// ;;; End:
|