<commit_before>/*
 * Copyright 2017-present Facebook, Inc.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *   http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#include <folly/concurrency/UnboundedQueue.h>
#include <folly/MPMCQueue.h>
#include <folly/ProducerConsumerQueue.h>
#include <folly/portability/GTest.h>

#include <boost/thread/barrier.hpp>
#include <glog/logging.h>

#include <atomic>
#include <thread>

DEFINE_bool(bench, false, "run benchmark");
DEFINE_int32(reps, 10, "number of reps");
DEFINE_int32(ops, 1000000, "number of operations per rep");
DEFINE_int64(capacity, 256 * 1024, "capacity");

template <typename T, bool MayBlock>
using USPSC = folly::USPSCQueue<T, MayBlock>;

template <typename T, bool MayBlock>
using UMPSC = folly::UMPSCQueue<T, MayBlock>;

template <typename T, bool MayBlock>
using USPMC = folly::USPMCQueue<T, MayBlock>;

template <typename T, bool MayBlock>
using UMPMC = folly::UMPMCQueue<T, MayBlock>;

template <template <typename, bool> class Q, bool MayBlock>
void basic_test() {
  Q<int, MayBlock> q;
  ASSERT_TRUE(q.empty());
  ASSERT_EQ(q.size(), 0);
  int v = -1;
  ASSERT_FALSE(q.try_dequeue(v));

  q.enqueue(1);
  ASSERT_FALSE(q.empty());
  ASSERT_EQ(q.size(), 1);

  q.enqueue(2);
  ASSERT_EQ(q.size(), 2);
  ASSERT_FALSE(q.empty());
<commit_msg>Some functions to look at UnboundedQueue inlined code<commit_after>/*
 * Copyright 2017-present Facebook, Inc.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *   http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#include <folly/concurrency/UnboundedQueue.h>
#include <folly/MPMCQueue.h>
#include <folly/ProducerConsumerQueue.h>
#include <folly/portability/GTest.h>

#include <boost/thread/barrier.hpp>
#include <glog/logging.h>

#include <atomic>
#include <thread>

DEFINE_bool(bench, false, "run benchmark");
DEFINE_int32(reps, 10, "number of reps");
DEFINE_int32(ops, 1000000, "number of operations per rep");
DEFINE_int64(capacity, 256 * 1024, "capacity");

template <typename T, bool MayBlock>
using USPSC = folly::USPSCQueue<T, MayBlock>;

template <typename T, bool MayBlock>
using UMPSC = folly::UMPSCQueue<T, MayBlock>;

template <typename T, bool MayBlock>
using USPMC = folly::USPMCQueue<T, MayBlock>;

template <typename T, bool MayBlock>
using UMPMC = folly::UMPMCQueue<T, MayBlock>;

// check functions for inspecting inlined native code

FOLLY_ATTR_WEAK void noop(folly::Optional<int>&&) {}

extern "C" void check_uspsc_mayblock_dequeue_ref(
    USPSC<int, true>& queue,
    int& item) {
  queue.dequeue(item);
}
extern "C" bool check_uspsc_mayblock_try_dequeue_ref(
    USPSC<int, true>& queue,
    int& item) {
  return queue.try_dequeue(item);
}
extern "C" bool check_uspsc_mayblock_try_dequeue_for_ref(
    USPSC<int, true>& queue,
    int& item,
    std::chrono::milliseconds const& timeout) {
  return queue.try_dequeue_for(item, timeout);
}
extern "C" bool check_uspsc_mayblock_try_dequeue_until_ref(
    USPSC<int, true>& queue,
    int& item,
    std::chrono::steady_clock::time_point const& deadline) {
  return queue.try_dequeue_until(item, deadline);
}

extern "C" int check_uspsc_mayblock_dequeue_ret(USPSC<int, true>& queue) {
  return queue.dequeue();
}
extern "C" void check_uspsc_mayblock_try_dequeue_ret(USPSC<int, true>& queue) {
  noop(queue.try_dequeue());
}
extern "C" void check_uspsc_mayblock_try_dequeue_for_ret(
    USPSC<int, true>& queue,
    std::chrono::milliseconds const& timeout) {
  noop(queue.try_dequeue_for(timeout));
}
extern "C" void check_uspsc_mayblock_try_dequeue_until_ret(
    USPSC<int, true>& queue,
    std::chrono::steady_clock::time_point const& deadline) {
  noop(queue.try_dequeue_until(deadline));
}

extern "C" void check_umpmc_mayblock_dequeue_ref(
    UMPMC<int, true>& queue,
    int& item) {
  queue.dequeue(item);
}
extern "C" bool check_umpmc_mayblock_try_dequeue_ref(
    UMPMC<int, true>& queue,
    int& item) {
  return queue.try_dequeue(item);
}
extern "C" bool check_umpmc_mayblock_try_dequeue_for_ref(
    UMPMC<int, true>& queue,
    int& item,
    std::chrono::milliseconds const& timeout) {
  return queue.try_dequeue_for(item, timeout);
}
extern "C" bool check_umpmc_mayblock_try_dequeue_until_ref(
    UMPMC<int, true>& queue,
    int& item,
    std::chrono::steady_clock::time_point const& deadline) {
  return queue.try_dequeue_until(item, deadline);
}

extern "C" int check_umpmc_mayblock_dequeue_ret(UMPMC<int, true>& queue) {
  return queue.dequeue();
}
extern "C" void check_umpmc_mayblock_try_dequeue_ret(UMPMC<int, true>& queue) {
  noop(queue.try_dequeue());
}
extern "C" void check_umpmc_mayblock_try_dequeue_for_ret(
    UMPMC<int, true>& queue,
    std::chrono::milliseconds const& timeout) {
  noop(queue.try_dequeue_for(timeout));
}
extern "C" void check_umpmc_mayblock_try_dequeue_until_ret(
    UMPMC<int, true>& queue,
    std::chrono::steady_clock::time_point const& deadline) {
  noop(queue.try_dequeue_until(deadline));
}

template <template <typename, bool> class Q, bool MayBlock>
void basic_test() {
  Q<int, MayBlock> q;
  ASSERT_TRUE(q.empty());
  ASSERT_EQ(q.size(), 0);
  int v = -1;
  ASSERT_FALSE(q.try_dequeue(v));

  q.enqueue(1);
  ASSERT_FALSE(q.empty());
  ASSERT_EQ(q.size(), 1);

  q.enqueue(2);
  ASSERT_EQ(q.size(), 2);
  ASSERT_FALSE(q.empty());

{'fraction_non_alphanumeric': 0.12473743738891582, 'fraction_numerical': 0.0116335433834222, 'mean_word_length': 5.290650406504065, 'pattern_counts': {'":': 0, '<': 58, '<?xml version=': 0, '>': 58, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4814386', 'n_tokens_mistral': 2260, 'n_tokens_neox': 2135, 'n_words': 559}