<commit_before>/*
 * Copyright(c) Sophist Solutions, Inc. 1990-2013.  All rights reserved
 */
#ifndef _Stroika_Foundation_Execution_BlockingQueue_inl_
#define _Stroika_Foundation_Execution_BlockingQueue_inl_    1


/*
 ********************************************************************************
 ***************************** Implementation Details ***************************
 ********************************************************************************
 */

namespace   Stroika {
    namespace   Foundation {
        namespace   Execution {


            /*
             ********************************************************************************
             ******************************** BlockingQueue<T> ******************************
             ********************************************************************************
             */
            template    <typename T>
            BlockingQueue<T>::BlockingQueue ()
                : fMutex_ ()
                , fDataAvailable_ ()
                , fQueue_ ()
            {
            }
            template    <typename T>
            void    BlockingQueue<T>::AddTail (T e, Time::DurationSecondsType timeout)
            {
                {
                    lock_guard<mutex> critSec (fMutex_);
                    fQueue_.AddTail (e);
                }
                fDataAvailable_.Set ();
            }
            template    <typename T>
            T       BlockingQueue<T>::RemoveHead (Time::DurationSecondsType timeout)
            {
                Time::DurationSecondsType   waitTil = Time::GetTickCount () + timeout;
                while (true) {
                    {
                        lock_guard<mutex> critSec (fMutex_);
                        if (not fQueue_.empty ()) {
                            return fQueue_.RemoveHead ();
                        }
                    }
                    fDataAvailable_.Wait (waitTil - Time::GetTickCount ());
                }
            }
            template    <typename T>
            Memory::Optional<T>     BlockingQueue<T>::RemoveHeadIfPossible (Time::DurationSecondsType timeout)
            {
                if (timeout <= 0.0) {
                    lock_guard<mutex> critSec (fMutex_);
                    if (fQueue_.empty ()) {
                        return Memory::Optional<T> ();
                    }
                    return fQueue_.RemoveHead ();
                }
                else {
                    // weak but adequate impl
                    try {
                        RemoveHead (timeout);
                    }
                    catch (...) {
                        return Memory::Optional<T> ();<commit_msg>minor bugfix to Execution/BlockingQueue<commit_after>/*
 * Copyright(c) Sophist Solutions, Inc. 1990-2013.  All rights reserved
 */
#ifndef _Stroika_Foundation_Execution_BlockingQueue_inl_
#define _Stroika_Foundation_Execution_BlockingQueue_inl_    1


/*
 ********************************************************************************
 ***************************** Implementation Details ***************************
 ********************************************************************************
 */

namespace   Stroika {
    namespace   Foundation {
        namespace   Execution {


            /*
             ********************************************************************************
             ******************************** BlockingQueue<T> ******************************
             ********************************************************************************
             */
            template    <typename T>
            BlockingQueue<T>::BlockingQueue ()
                : fMutex_ ()
                , fDataAvailable_ ()
                , fQueue_ ()
            {
            }
            template    <typename T>
            void    BlockingQueue<T>::AddTail (T e, Time::DurationSecondsType timeout)
            {
                {
                    lock_guard<mutex> critSec (fMutex_);
                    fQueue_.AddTail (e);
                }
                fDataAvailable_.Set ();
            }
            template    <typename T>
            T       BlockingQueue<T>::RemoveHead (Time::DurationSecondsType timeout)
            {
                Time::DurationSecondsType   waitTil = Time::GetTickCount () + timeout;
                while (true) {
                    {
                        lock_guard<mutex> critSec (fMutex_);
                        if (not fQueue_.empty ()) {
                            return fQueue_.RemoveHead ();
                        }
                    }
                    fDataAvailable_.Wait (waitTil - Time::GetTickCount ());
                }
            }
            template    <typename T>
            Memory::Optional<T>     BlockingQueue<T>::RemoveHeadIfPossible (Time::DurationSecondsType timeout)
            {
                if (timeout <= 0.0) {
                    lock_guard<mutex> critSec (fMutex_);
                    if (fQueue_.empty ()) {
                        return Memory::Optional<T> ();
                    }
                    return fQueue_.RemoveHead ();
                }
                else {
                    // weak but adequate impl
                    try {
                        return RemoveHead (timeout);
                    }
                    catch (...) {
                        return Memory::Optional<T> ();
{'fraction_non_alphanumeric': 0.23181235110866777, 'fraction_numerical': 0.004031519149715961, 'mean_word_length': 1.4497307001795332, 'pattern_counts': {'":': 0, '<': 35, '<?xml version=': 0, '>': 33, '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': '1371168', 'n_tokens_mistral': 1200, 'n_tokens_neox': 1086, 'n_words': 202}