<commit_before>/**
 * @file
 */
#include "libbirch/memory.hpp"

#include "libbirch/thread.hpp"
#include "libbirch/Atomic.hpp"
#include "libbirch/Any.hpp"
#include "libbirch/Marker.hpp"
#include "libbirch/Scanner.hpp"
#include "libbirch/Collector.hpp"

#include <vector>

/**
 * Possible roots list for each thread.
 */
static thread_local std::vector<libbirch::Any*> possible_roots;

/**
 * Unreachable list for each thread.
 */
static thread_local std::vector<libbirch::Any*> unreachables;

/**
 * Copy flag for each thread.
 */
static thread_local bool copy_flag = false;

/**
 * Deregistration count for reach thread.
 */
static thread_local int ndereg = 0;

/**
 * Number of deregistrations in a thread before trimming the possible-roots
 * list, deallocating any objects with zero reference count.
 */
static const int DEREG_PERIOD = 32;

void libbirch::register_possible_root(Any* o) {
  possible_roots.push_back(o);
}

void libbirch::deregister_possible_root(Any* o) {
  assert(o->numShared_() == 0);
  if (!possible_roots.empty()) {
    if (possible_roots.back() == o) {
      /* easy to deallocate an object if it was the most-recently added */
      possible_roots.pop_back();
      o->deallocate_();
    } else if (++ndereg == DEREG_PERIOD) {
      /* periodically trim the possible-roots list, deallocating any objects
       * with zero reference count */
      int j = 0;
      for (int i = 0; i < (int)possible_roots.size(); ++i) {
        auto o1 = possible_roots[i];
        if (o1->numShared_() == 0) {
          o1->deallocate_();  // deallocation was deferred
        } else if (o1->isPossibleRoot_()) {
          possible_roots[j++] = o1;
        } else {
          o1->unbuffer_();  // not a root, mark as no longer in the buffer
        }
      }
      possible_roots.resize(j);

      /* reset count */
      ndereg = 0;
    }
  }
}

bool libbirch::contains_possible_root(Any* o) {
  return std::find(possible_roots.begin(), possible_roots.end(), o) !=
      possible_roots.end();
}

void libbirch::register_unreachable(Any* o) {<commit_msg>Removed trimming of possible-roots list, as not thread safe.<commit_after>/**
 * @file
 */
#include "libbirch/memory.hpp"

#include "libbirch/thread.hpp"
#include "libbirch/Atomic.hpp"
#include "libbirch/Any.hpp"
#include "libbirch/Marker.hpp"
#include "libbirch/Scanner.hpp"
#include "libbirch/Collector.hpp"

#include <vector>

/**
 * Possible roots list for each thread.
 */
static thread_local std::vector<libbirch::Any*> possible_roots;

/**
 * Unreachable list for each thread.
 */
static thread_local std::vector<libbirch::Any*> unreachables;

/**
 * Copy flag for each thread.
 */
static thread_local bool copy_flag = false;

/**
 * Deregistration count for reach thread.
 */
static thread_local int ndereg = 0;

void libbirch::register_possible_root(Any* o) {
  possible_roots.push_back(o);
}

void libbirch::deregister_possible_root(Any* o) {
  assert(o->numShared_() == 0);
  if (!possible_roots.empty() && possible_roots.back() == o) {
    /* easy to deallocate an object if it was the most-recently added */
    possible_roots.pop_back();
    o->deallocate_();
  }
}

bool libbirch::contains_possible_root(Any* o) {
  return std::find(possible_roots.begin(), possible_roots.end(), o) !=
      possible_roots.end();
}

void libbirch::register_unreachable(Any* o) {
{'fraction_non_alphanumeric': 0.1406764441783897, 'fraction_numerical': 0.004788985333732416, 'mean_word_length': 3.70042194092827, 'pattern_counts': {'":': 0, '<': 10, '<?xml version=': 0, '>': 17, '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': '2985423', 'n_tokens_mistral': 1193, 'n_tokens_neox': 1146, 'n_words': 278}