<commit_before>#ifndef UTIL_TINY_MESSAGE_QUEUE_H
#define UTIL_TINY_MESSAGE_QUEUE_H
/**
 * @file util/TinyMessageQueue.h
 * @author <NAME>
 * @date Created <2009-11-01 21:50:36>
 * @date Updated <2009-11-01 23:00:42>
 */

#include <boost/thread/condition_variable.hpp>
#include <boost/thread/locks.hpp>
#include <boost/thread/mutex.hpp>
#include <boost/thread/thread.hpp>

#include <queue>
namespace izenelib {
namespace util {

template<typename T>
class TinyMessageQueue
{
public:
    /**
     * @brief gets one element from queue
     * @param[out] t
     * Wait if queue is empty
     */
    void pop(T& t);

    /**
     * @brief appends one element into queue
     */
    void push(const T& t);

    void clear()
    {
        boost::unique_lock<boost::mutex> lock(mutex_);
        queue_.clear();
    }

private:
    std::deque<T> queue_;

    boost::mutex mutex_;
    boost::condition_variable cond_;
};

template<typename T>
void TinyMessageQueue<T>::pop(T& t)
{
    boost::unique_lock<boost::mutex> lock(mutex_);
    while(queue_.empty())
    {
        cond_.wait(lock);<commit_msg>add function empty in TinyMessageQueue<commit_after>#ifndef UTIL_TINY_MESSAGE_QUEUE_H
#define UTIL_TINY_MESSAGE_QUEUE_H
/**
 * @file util/TinyMessageQueue.h
 * @author <NAME>
 * @date Created <2009-11-01 21:50:36>
 * @date Updated <2009-11-04 17:14:51>
 */

#include <boost/thread/condition_variable.hpp>
#include <boost/thread/locks.hpp>
#include <boost/thread/mutex.hpp>
#include <boost/thread/thread.hpp>

#include <queue>
namespace izenelib {
namespace util {

template<typename T>
class TinyMessageQueue
{
public:
    /**
     * @brief gets one element from queue
     * @param[out] t
     * Wait if queue is empty
     */
    void pop(T& t);

    /**
     * @brief appends one element into queue
     */
    void push(const T& t);

    void clear()
    {
        boost::unique_lock<boost::mutex> lock(mutex_);
        queue_.clear();
    }

    bool empty() const
    {
        return queue_.empty();
    }

private:
    std::deque<T> queue_;

    boost::mutex mutex_;
    boost::condition_variable cond_;
};

template<typename T>
void TinyMessageQueue<T>::pop(T& t)
{
    boost::unique_lock<boost::mutex> lock(mutex_);
    while(queue_.empty())
    {
        cond_.wait(lock);
{'fraction_non_alphanumeric': 0.13896218117854, 'fraction_numerical': 0.024626209322779244, 'mean_word_length': 3.276315789473684, 'pattern_counts': {'":': 0, '<': 31, '<?xml version=': 0, '>': 31, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1760793', 'n_tokens_mistral': 832, 'n_tokens_neox': 777, 'n_words': 172}