<commit_before>#include <bench/bench.hpp>
#include <sal/intrusive_queue.hpp>
#include <sal/spinlock.hpp>
#include <algorithm>
#include <atomic>
#include <iostream>
#include <thread>
#include <vector>
#include <set>


namespace {

using namespace std::chrono;


// configuration
size_t run = 10;
size_t count = 10'000'000;
size_t producers = 1, consumers = 1;
std::string type = "mpsc";

const std::set<std::string> valid_types{
  "mpsc",
  "spsc",
};


template <typename SyncPolicy>
struct foo
{
  bool stop = false;
  typename SyncPolicy::intrusive_queue_hook_t hook{};
  using queue = sal::intrusive_queue_t<foo, SyncPolicy, &foo::hook>;
};



template <typename SyncPolicy>
milliseconds single_run ()
{
  // preallocate items and create queue
  std::vector<foo<SyncPolicy>> nodes(count);
  typename foo<SyncPolicy>::queue q;

  std::vector<std::thread> consumer_threads, producer_threads;
  auto start_time = bench::start();

  // start consumers
  for (size_t i = 0;  i != consumers;  ++i)
  {
    consumer_threads.emplace_back(
      [&]
      {
        for (size_t i = 0;  /**/;  ++i)
        {
          if (auto n = q.try_pop())
          {
            if (n->stop)
            {
              break;
            }
          }
          else
          {
            sal::adaptive_spin<100>(i);
          }
        }
      }
    );
  }

  // start producers
  std::atomic<size_t> current{};
  for (size_t i = 0;  i != producers;  ++i)
  {
    producer_threads.emplace_back(
      [&, i]
      {
        for (;;)
        {
          auto x = current++;
          if (x < count)
          {
            q.push(&nodes[x]);
          }
          else
          {
            return;
          }
        }
      }
    );
  }

  // wait producers to finish
  for (auto &thread: producer_threads)
  {
    thread.join();<commit_msg>Fix clang warning about unused captured variable in lambda<commit_after>#include <bench/bench.hpp>
#include <sal/intrusive_queue.hpp>
#include <sal/spinlock.hpp>
#include <algorithm>
#include <atomic>
#include <iostream>
#include <thread>
#include <vector>
#include <set>


namespace {

using namespace std::chrono;


// configuration
size_t run = 10;
size_t count = 10'000'000;
size_t producers = 1, consumers = 1;
std::string type = "mpsc";

const std::set<std::string> valid_types{
  "mpsc",
  "spsc",
};


template <typename SyncPolicy>
struct foo
{
  bool stop = false;
  typename SyncPolicy::intrusive_queue_hook_t hook{};
  using queue = sal::intrusive_queue_t<foo, SyncPolicy, &foo::hook>;
};



template <typename SyncPolicy>
milliseconds single_run ()
{
  // preallocate items and create queue
  std::vector<foo<SyncPolicy>> nodes(count);
  typename foo<SyncPolicy>::queue q;

  std::vector<std::thread> consumer_threads, producer_threads;
  auto start_time = bench::start();

  // start consumers
  for (size_t i = 0;  i != consumers;  ++i)
  {
    consumer_threads.emplace_back(
      [&]
      {
        for (size_t i = 0;  /**/;  ++i)
        {
          if (auto n = q.try_pop())
          {
            if (n->stop)
            {
              break;
            }
          }
          else
          {
            sal::adaptive_spin<100>(i);
          }
        }
      }
    );
  }

  // start producers
  std::atomic<size_t> current{};
  for (size_t i = 0;  i != producers;  ++i)
  {
    producer_threads.emplace_back(
      [&]
      {
        for (;;)
        {
          auto x = current++;
          if (x < count)
          {
            q.push(&nodes[x]);
          }
          else
          {
            return;
          }
        }
      }
    );
  }

  // wait producers to finish
  for (auto &thread: producer_threads)
  {
    thread.join();
{'fraction_non_alphanumeric': 0.13788451160280626, 'fraction_numerical': 0.009713977334052886, 'mean_word_length': 2.07379767827529, 'pattern_counts': {'":': 0, '<': 43, '<?xml version=': 0, '>': 43, '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': '7287350', 'n_tokens_mistral': 1288, 'n_tokens_neox': 1235, 'n_words': 276}