<commit_before>#pragma once

#include "condition.hpp"
#include "logging.hpp"
#include "../std/list.hpp"

#include "threaded_container.hpp"

template <typename T>
class ThreadedList : public ThreadedContainer
{
private:

  list<T> m_list;
  bool m_isEmpty;
  string m_resName;

public:

  ThreadedList()
    : m_isEmpty(true)
  {}

  template <typename Fn>
  void ProcessList(Fn const & fn)
  {
    threads::ConditionGuard g(m_Cond);

    bool hadElements = !m_list.empty();

    fn(m_list);

    bool hasElements = !m_list.empty();

    m_isEmpty = !hasElements;

    if (!hadElements && hasElements)
      m_Cond.Signal();
  }

  void PushBack(T const & t)
  {
    threads::ConditionGuard g(m_Cond);

    bool doSignal = m_list.empty();

    m_list.push_back(t);
    m_isEmpty = false;

    if (doSignal)
      m_Cond.Signal();
  }

  void PushFront(T const & t)
  {
    threads::ConditionGuard g(m_Cond);

    bool doSignal = m_list.empty();

    m_list.push_front(t);
    m_isEmpty = false;

    if (doSignal)
      m_Cond.Signal();
  }<commit_msg>fixed deadlock in CoverageGenerator related to Wait/Signal logic in ThreadedList<commit_after>#pragma once

#include "condition.hpp"
#include "logging.hpp"
#include "../std/list.hpp"

#include "threaded_container.hpp"

template <typename T>
class ThreadedList : public ThreadedContainer
{
private:

  list<T> m_list;
  bool m_isEmpty;
  string m_resName;

public:

  ThreadedList()
    : m_isEmpty(true)
  {}

  template <typename Fn>
  void ProcessList(Fn const & fn)
  {
    threads::ConditionGuard g(m_Cond);

    bool hadElements = !m_list.empty();

    fn(m_list);

    bool hasElements = !m_list.empty();

    m_isEmpty = !hasElements;

    if (!hadElements && hasElements)
      m_Cond.Signal(true);
  }

  void PushBack(T const & t)
  {
    threads::ConditionGuard g(m_Cond);

    bool doSignal = m_list.empty();

    m_list.push_back(t);
    m_isEmpty = false;

    if (doSignal)
      m_Cond.Signal(true);
  }

  void PushFront(T const & t)
  {
    threads::ConditionGuard g(m_Cond);

    bool doSignal = m_list.empty();

    m_list.push_front(t);
    m_isEmpty = false;

    if (doSignal)
      m_Cond.Signal(true);
  }
{'fraction_non_alphanumeric': 0.12425492893168272, 'fraction_numerical': 0.0, 'mean_word_length': 3.236893203883495, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 9, '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': '4295183', 'n_tokens_mistral': 799, 'n_tokens_neox': 761, 'n_words': 167}