/* -*-c++-*- header - Open Producer - Copyright (C) 2002 Don Burns
 * Distributed under the terms of the GNU LIBRARY GENERAL PUBLIC LICENSE (LGPL)
 * as published by the Free Software Foundation.
 */
#ifndef _PRODUCER_BLOCKING_QUEUE
#define _PRODUCER_BLOCKING_QUEUE 1

#include <deque>

#include <Producer/Referenced>
#include <Producer/Block>

#include <OpenThreads/Mutex>


namespace Producer {

template <class T>
class BlockingQueue : public Referenced, public std::deque<T>
{
    public:
        BlockingQueue() 
        { 
            _block = new Producer::Block;
        }

        void waitWhileEmpty() 
        {
            if( empty() )
                _block->reset();
            _block->block();
        }

        void push_back(const T &val)
        {
            _mut.lock();
#if defined(WIN32) && !defined(__GNUC__)
using namespace std;
            deque<T>::push_back(val);
#else
            std::deque<T>::push_back(val);
#endif
            _block->release();
            _mut.unlock();
        }

    protected:
        ~BlockingQueue() {}

    private:
        Producer::ref_ptr<Block> _block;
        OpenThreads::Mutex _mut;
};

}

#endif
