proxygen
|
#include <folly/MPMCQueue.h>
#include <folly/Format.h>
#include <folly/Memory.h>
#include <folly/portability/GTest.h>
#include <folly/portability/SysResource.h>
#include <folly/portability/SysTime.h>
#include <folly/portability/Unistd.h>
#include <folly/stop_watch.h>
#include <folly/test/DeterministicSchedule.h>
#include <boost/intrusive_ptr.hpp>
#include <boost/thread/barrier.hpp>
#include <functional>
#include <memory>
#include <thread>
#include <utility>
Go to the source code of this file.
Classes | |
struct | RefCounted |
struct | WriteMethodCaller< Q > |
struct | BlockingWriteCaller< Q > |
struct | WriteIfNotFullCaller< Q > |
struct | WriteCaller< Q > |
struct | TryWriteUntilCaller< Q, Clock, Duration > |
struct | Lifecycle< R > |
Macros | |
#define | PC_BENCH(q, np, nc, ...) producerConsumerBench(q, #q, (np), (nc), __VA_ARGS__) |
#define | LIFECYCLE_STEP(...) lc_step(__LINE__, __VA_ARGS__) |
Typedefs | |
typedef DeterministicSchedule | DSched |
Enumerations | |
enum | LifecycleEvent { NOTHING = -1, DEFAULT_CONSTRUCTOR, COPY_CONSTRUCTOR, MOVE_CONSTRUCTOR, TWO_ARG_CONSTRUCTOR, COPY_OPERATOR, MOVE_OPERATOR, DESTRUCTOR, MAX_LIFECYCLE_EVENT } |
Functions | |
template<template< typename > class Atom> | |
void | run_mt_sequencer_thread (int numThreads, int numOps, uint32_t init, TurnSequencer< Atom > &seq, Atom< uint32_t > &spinThreshold, int &prev, int i) |
template<template< typename > class Atom> | |
void | run_mt_sequencer_test (int numThreads, int numOps, uint32_t init) |
TEST (MPMCQueue, sequencer) | |
TEST (MPMCQueue, sequencer_emulated_futex) | |
TEST (MPMCQueue, sequencer_deterministic) | |
template<bool Dynamic = false, typename T > | |
void | runElementTypeTest (T &&src) |
void | intrusive_ptr_add_ref (RefCounted const *p) |
void | intrusive_ptr_release (RefCounted const *p) |
TEST (MPMCQueue, lots_of_element_types) | |
TEST (MPMCQueue, lots_of_element_types_dynamic) | |
TEST (MPMCQueue, single_thread_enqdeq) | |
TEST (MPMCQueue, tryenq_capacity_test) | |
TEST (MPMCQueue, enq_capacity_test) | |
template<template< typename > class Atom, bool Dynamic = false> | |
void | runTryEnqDeqThread (int numThreads, int n, MPMCQueue< int, Atom, Dynamic > &cq, std::atomic< uint64_t > &sum, int t) |
template<template< typename > class Atom, bool Dynamic = false> | |
void | runTryEnqDeqTest (int numThreads, int numOps) |
TEST (MPMCQueue, mt_try_enq_deq) | |
TEST (MPMCQueue, mt_try_enq_deq_dynamic) | |
TEST (MPMCQueue, mt_try_enq_deq_emulated_futex) | |
TEST (MPMCQueue, mt_try_enq_deq_emulated_futex_dynamic) | |
TEST (MPMCQueue, mt_try_enq_deq_deterministic) | |
uint64_t | nowMicro () |
template<typename Q > | |
string | producerConsumerBench (Q &&queue, string qName, int numProducers, int numConsumers, int numOps, WriteMethodCaller< Q > &writer, bool ignoreContents=false) |
template<bool Dynamic = false> | |
void | runMtProdConsDeterministic (long seed) |
void | runMtProdConsDeterministicDynamic (long seed, uint32_t prods, uint32_t cons, uint32_t numOps, size_t cap, size_t minCap, size_t mult) |
TEST (MPMCQueue, mt_prod_cons_deterministic) | |
TEST (MPMCQueue, mt_prod_cons_deterministic_dynamic) | |
template<typename T > | |
void | setFromEnv (T &var, const char *envvar) |
TEST (MPMCQueue, mt_prod_cons_deterministic_dynamic_with_arguments) | |
template<bool Dynamic = false> | |
void | runMtProdCons () |
TEST (MPMCQueue, mt_prod_cons) | |
TEST (MPMCQueue, mt_prod_cons_dynamic) | |
template<bool Dynamic = false> | |
void | runMtProdConsEmulatedFutex () |
TEST (MPMCQueue, mt_prod_cons_emulated_futex) | |
TEST (MPMCQueue, mt_prod_cons_emulated_futex_dynamic) | |
template<template< typename > class Atom, bool Dynamic = false> | |
void | runNeverFailThread (int numThreads, int n, MPMCQueue< int, Atom, Dynamic > &cq, std::atomic< uint64_t > &sum, int t) |
template<template< typename > class Atom, bool Dynamic = false> | |
uint64_t | runNeverFailTest (int numThreads, int numOps) |
template<template< typename > class Atom, bool Dynamic = false> | |
void | runMtNeverFail (std::vector< int > &nts, int n) |
TEST (MPMCQueue, mt_never_fail) | |
TEST (MPMCQueue, mt_never_fail_emulated_futex) | |
template<bool Dynamic = false> | |
void | runMtNeverFailDeterministic (std::vector< int > &nts, int n, long seed) |
TEST (MPMCQueue, mt_never_fail_deterministic) | |
template<class Clock , template< typename > class Atom, bool Dynamic> | |
void | runNeverFailUntilThread (int numThreads, int n, MPMCQueue< int, Atom, Dynamic > &cq, std::atomic< uint64_t > &sum, int t) |
template<class Clock , template< typename > class Atom, bool Dynamic = false> | |
uint64_t | runNeverFailTest (int numThreads, int numOps) |
template<bool Dynamic = false> | |
void | runMtNeverFailUntilSystem (std::vector< int > &nts, int n) |
TEST (MPMCQueue, mt_never_fail_until_system) | |
template<bool Dynamic = false> | |
void | runMtNeverFailUntilSteady (std::vector< int > &nts, int n) |
TEST (MPMCQueue, mt_never_fail_until_steady) | |
static int | lc_outstanding () |
static void | lc_snap () |
static void | lc_step (int lineno, int what=NOTHING, int what2=NOTHING) |
template<typename R > | |
void | runPerfectForwardingTest () |
TEST (MPMCQueue, perfect_forwarding) | |
TEST (MPMCQueue, perfect_forwarding_relocatable) | |
template<bool Dynamic = false> | |
void | run_queue_moving () |
TEST (MPMCQueue, queue_moving) | |
TEST (MPMCQueue, queue_moving_dynamic) | |
TEST (MPMCQueue, explicit_zero_capacity_fail) | |
template<bool Dynamic> | |
void | testTryReadUntil () |
template<bool Dynamic> | |
void | testTryWriteUntil () |
TEST (MPMCQueue, try_read_until) | |
TEST (MPMCQueue, try_read_until_dynamic) | |
TEST (MPMCQueue, try_write_until) | |
TEST (MPMCQueue, try_write_until_dynamic) | |
template<bool Dynamic> | |
void | testTimeout (MPMCQueue< int, std::atomic, Dynamic > &q) |
TEST (MPMCQueue, try_write_until_timeout) | |
TEST (MPMCQueue, must_fail_try_write_until_dynamic) | |
Variables | |
static FOLLY_TLS int | lc_counts [MAX_LIFECYCLE_EVENT] |
static FOLLY_TLS int | lc_prev [MAX_LIFECYCLE_EVENT] |
#define LIFECYCLE_STEP | ( | ... | ) | lc_step(__LINE__, __VA_ARGS__) |
Definition at line 918 of file MPMCQueueTest.cpp.
Referenced by run_queue_moving(), and runPerfectForwardingTest().
#define PC_BENCH | ( | q, | |
np, | |||
nc, | |||
... | |||
) | producerConsumerBench(q, #q, (np), (nc), __VA_ARGS__) |
Definition at line 640 of file MPMCQueueTest.cpp.
Referenced by runMtProdCons(), and runMtProdConsEmulatedFutex().
typedef DeterministicSchedule DSched |
Definition at line 47 of file MPMCQueueTest.cpp.
enum LifecycleEvent |
Enumerator | |
---|---|
NOTHING | |
DEFAULT_CONSTRUCTOR | |
COPY_CONSTRUCTOR | |
MOVE_CONSTRUCTOR | |
TWO_ARG_CONSTRUCTOR | |
COPY_OPERATOR | |
MOVE_OPERATOR | |
DESTRUCTOR | |
MAX_LIFECYCLE_EVENT |
Definition at line 891 of file MPMCQueueTest.cpp.
void intrusive_ptr_add_ref | ( | RefCounted const * | p | ) |
Definition at line 142 of file MPMCQueueTest.cpp.
References RefCounted::rc.
void intrusive_ptr_release | ( | RefCounted const * | p | ) |
Definition at line 146 of file MPMCQueueTest.cpp.
References RefCounted::rc.
|
static |
Definition at line 906 of file MPMCQueueTest.cpp.
References COPY_CONSTRUCTOR, DEFAULT_CONSTRUCTOR, DESTRUCTOR, lc_counts, MOVE_CONSTRUCTOR, and TWO_ARG_CONSTRUCTOR.
Referenced by run_queue_moving(), runPerfectForwardingTest(), and Lifecycle< R >::~Lifecycle().
|
static |
Definition at line 912 of file MPMCQueueTest.cpp.
References i, lc_counts, lc_prev, and MAX_LIFECYCLE_EVENT.
Referenced by lc_step(), run_queue_moving(), and runPerfectForwardingTest().
Definition at line 920 of file MPMCQueueTest.cpp.
References EXPECT_EQ, i, lc_counts, lc_prev, lc_snap(), and MAX_LIFECYCLE_EVENT.
uint64_t nowMicro | ( | ) |
Definition at line 360 of file MPMCQueueTest.cpp.
References uint64_t.
Referenced by producerConsumerBench(), and runNeverFailTest().
string producerConsumerBench | ( | Q && | queue, |
string | qName, | ||
int | numProducers, | ||
int | numConsumers, | ||
int | numOps, | ||
WriteMethodCaller< Q > & | writer, | ||
bool | ignoreContents = false |
||
) |
Definition at line 424 of file MPMCQueueTest.cpp.
References allocated, WriteMethodCaller< Q >::callWrite(), upload::dest, EXPECT_EQ, EXPECT_FALSE, failed, i, folly::test::DeterministicSchedule::join(), WriteMethodCaller< Q >::methodName(), nowMicro(), folly::sformat(), sum(), folly::pushmi::detail::t, folly::test::DeterministicSchedule::thread(), and uint64_t.
Referenced by runMtProdConsDeterministic(), and runMtProdConsDeterministicDynamic().
void run_mt_sequencer_test | ( | int | numThreads, |
int | numOps, | ||
uint32_t | init | ||
) |
Definition at line 67 of file MPMCQueueTest.cpp.
References folly::netops::bind(), EXPECT_EQ, i, folly::test::DeterministicSchedule::join(), folly::gen::seq(), folly::test::DeterministicSchedule::thread(), and threads.
void run_mt_sequencer_thread | ( | int | numThreads, |
int | numOps, | ||
uint32_t | init, | ||
TurnSequencer< Atom > & | seq, | ||
Atom< uint32_t > & | spinThreshold, | ||
int & | prev, | ||
int | i | ||
) |
Definition at line 50 of file MPMCQueueTest.cpp.
References Atom, and EXPECT_EQ.
void run_queue_moving | ( | ) |
Definition at line 1056 of file MPMCQueueTest.cpp.
References a, b, c, COPY_CONSTRUCTOR, DEFAULT_CONSTRUCTOR, DESTRUCTOR, EXPECT_EQ, EXPECT_TRUE, lc_outstanding(), lc_snap(), LIFECYCLE_STEP, folly::gen::move, MOVE_CONSTRUCTOR, MOVE_OPERATOR, NOTHING, and folly::f14::swap().
Referenced by TEST().
void runElementTypeTest | ( | T && | src | ) |
Definition at line 112 of file MPMCQueueTest.cpp.
References upload::dest, EXPECT_TRUE, folly::gen::move, now(), and T.
Referenced by TEST().
void runMtNeverFail | ( | std::vector< int > & | nts, |
int | n | ||
) |
void runMtNeverFailDeterministic | ( | std::vector< int > & | nts, |
int | n, | ||
long | seed | ||
) |
Definition at line 787 of file MPMCQueueTest.cpp.
References folly::INFO, seed, folly::test::DeterministicSchedule::uniform(), and folly::test::DeterministicSchedule::uniformSubset().
Referenced by TEST().
void runMtNeverFailUntilSteady | ( | std::vector< int > & | nts, |
int | n | ||
) |
Definition at line 875 of file MPMCQueueTest.cpp.
References folly::INFO, and uint64_t.
Referenced by TEST().
void runMtNeverFailUntilSystem | ( | std::vector< int > & | nts, |
int | n | ||
) |
Definition at line 858 of file MPMCQueueTest.cpp.
References folly::INFO, and uint64_t.
Referenced by TEST().
void runMtProdCons | ( | ) |
Definition at line 644 of file MPMCQueueTest.cpp.
References folly::INFO, folly::make_unique(), PC_BENCH, and setFromEnv().
Referenced by TEST().
void runMtProdConsDeterministic | ( | long | seed | ) |
Definition at line 504 of file MPMCQueueTest.cpp.
References folly::INFO, folly::make_unique(), producerConsumerBench(), and folly::test::DeterministicSchedule::uniform().
Referenced by TEST().
void runMtProdConsDeterministicDynamic | ( | long | seed, |
uint32_t | prods, | ||
uint32_t | cons, | ||
uint32_t | numOps, | ||
size_t | cap, | ||
size_t | minCap, | ||
size_t | mult | ||
) |
Definition at line 569 of file MPMCQueueTest.cpp.
References folly::INFO, folly::make_unique(), producerConsumerBench(), and folly::test::DeterministicSchedule::uniform().
Referenced by TEST().
void runMtProdConsEmulatedFutex | ( | ) |
Definition at line 679 of file MPMCQueueTest.cpp.
References folly::INFO, folly::make_unique(), and PC_BENCH.
Referenced by TEST().
uint64_t runNeverFailTest | ( | int | numThreads, |
int | numOps | ||
) |
Definition at line 733 of file MPMCQueueTest.cpp.
References Atom, folly::netops::bind(), EXPECT_EQ, EXPECT_TRUE, folly::test::DeterministicSchedule::join(), nowMicro(), sum(), folly::pushmi::detail::t, folly::test::DeterministicSchedule::thread(), threads, and uint64_t.
uint64_t runNeverFailTest | ( | int | numThreads, |
int | numOps | ||
) |
Definition at line 830 of file MPMCQueueTest.cpp.
References folly::netops::bind(), EXPECT_EQ, EXPECT_TRUE, folly::test::DeterministicSchedule::join(), nowMicro(), sum(), folly::pushmi::detail::t, folly::test::DeterministicSchedule::thread(), threads, and uint64_t.
void runNeverFailThread | ( | int | numThreads, |
int | n, | ||
MPMCQueue< int, Atom, Dynamic > & | cq, | ||
std::atomic< uint64_t > & | sum, | ||
int | t | ||
) |
Definition at line 713 of file MPMCQueueTest.cpp.
References Atom, upload::dest, EXPECT_TRUE, i, and uint64_t.
void runNeverFailUntilThread | ( | int | numThreads, |
int | n, | ||
MPMCQueue< int, Atom, Dynamic > & | cq, | ||
std::atomic< uint64_t > & | sum, | ||
int | t | ||
) |
Definition at line 809 of file MPMCQueueTest.cpp.
References Atom, upload::dest, EXPECT_TRUE, i, now(), and uint64_t.
void runPerfectForwardingTest | ( | ) |
Definition at line 973 of file MPMCQueueTest.cpp.
References COPY_CONSTRUCTOR, DEFAULT_CONSTRUCTOR, DESTRUCTOR, EXPECT_EQ, EXPECT_FALSE, EXPECT_TRUE, i, lc_outstanding(), lc_snap(), LIFECYCLE_STEP, folly::gen::move, MOVE_CONSTRUCTOR, MOVE_OPERATOR, NOTHING, TWO_ARG_CONSTRUCTOR, and value.
void runTryEnqDeqTest | ( | int | numThreads, |
int | numOps | ||
) |
Definition at line 272 of file MPMCQueueTest.cpp.
References folly::netops::bind(), EXPECT_EQ, EXPECT_TRUE, folly::test::DeterministicSchedule::join(), sum(), folly::pushmi::detail::t, folly::test::DeterministicSchedule::thread(), threads, and uint64_t.
Referenced by TEST().
void runTryEnqDeqThread | ( | int | numThreads, |
int | n, | ||
MPMCQueue< int, Atom, Dynamic > & | cq, | ||
std::atomic< uint64_t > & | sum, | ||
int | t | ||
) |
Definition at line 245 of file MPMCQueueTest.cpp.
References Atom, folly::pushmi::detail::t, and uint64_t.
void setFromEnv | ( | T & | var, |
const char * | envvar | ||
) |
Definition at line 614 of file MPMCQueueTest.cpp.
Referenced by runMtProdCons(), and TEST().
TEST | ( | MPMCQueue | , |
sequencer | |||
) |
Definition at line 92 of file MPMCQueueTest.cpp.
TEST | ( | MPMCQueue | , |
sequencer_emulated_futex | |||
) |
Definition at line 98 of file MPMCQueueTest.cpp.
TEST | ( | MPMCQueue | , |
sequencer_deterministic | |||
) |
Definition at line 104 of file MPMCQueueTest.cpp.
References folly::test::DeterministicSchedule::uniform().
TEST | ( | MPMCQueue | , |
lots_of_element_types | |||
) |
Definition at line 152 of file MPMCQueueTest.cpp.
References RefCounted::active_instances, EXPECT_EQ, and runElementTypeTest().
TEST | ( | MPMCQueue | , |
lots_of_element_types_dynamic | |||
) |
Definition at line 163 of file MPMCQueueTest.cpp.
References RefCounted::active_instances, EXPECT_EQ, RefCounted::RefCounted(), and string.
TEST | ( | MPMCQueue | , |
single_thread_enqdeq | |||
) |
Definition at line 174 of file MPMCQueueTest.cpp.
References upload::dest, EXPECT_EQ, EXPECT_FALSE, EXPECT_TRUE, and i.
TEST | ( | MPMCQueue | , |
tryenq_capacity_test | |||
) |
Definition at line 207 of file MPMCQueueTest.cpp.
References EXPECT_FALSE, EXPECT_TRUE, and i.
TEST | ( | MPMCQueue | , |
enq_capacity_test | |||
) |
Definition at line 220 of file MPMCQueueTest.cpp.
References Atom, dummy(), EXPECT_EQ, i, folly::pushmi::detail::t, and folly::when().
TEST | ( | MPMCQueue | , |
mt_try_enq_deq | |||
) |
Definition at line 297 of file MPMCQueueTest.cpp.
TEST | ( | MPMCQueue | , |
mt_try_enq_deq_dynamic | |||
) |
TEST | ( | MPMCQueue | , |
mt_try_enq_deq_emulated_futex | |||
) |
Definition at line 315 of file MPMCQueueTest.cpp.
TEST | ( | MPMCQueue | , |
mt_try_enq_deq_emulated_futex_dynamic | |||
) |
Definition at line 324 of file MPMCQueueTest.cpp.
References runTryEnqDeqTest().
TEST | ( | MPMCQueue | , |
mt_try_enq_deq_deterministic | |||
) |
Definition at line 333 of file MPMCQueueTest.cpp.
References folly::INFO, runTryEnqDeqTest(), seed, folly::test::DeterministicSchedule::uniform(), and folly::test::DeterministicSchedule::uniformSubset().
TEST | ( | MPMCQueue | , |
mt_prod_cons_deterministic | |||
) |
Definition at line 605 of file MPMCQueueTest.cpp.
References runMtProdConsDeterministic().
TEST | ( | MPMCQueue | , |
mt_prod_cons_deterministic_dynamic | |||
) |
Definition at line 609 of file MPMCQueueTest.cpp.
TEST | ( | MPMCQueue | , |
mt_prod_cons_deterministic_dynamic_with_arguments | |||
) |
Definition at line 621 of file MPMCQueueTest.cpp.
References runMtProdConsDeterministicDynamic(), seed, setFromEnv(), and uint32_t.
TEST | ( | MPMCQueue | , |
mt_prod_cons | |||
) |
Definition at line 670 of file MPMCQueueTest.cpp.
References runMtProdCons().
TEST | ( | MPMCQueue | , |
mt_prod_cons_dynamic | |||
) |
TEST | ( | MPMCQueue | , |
mt_prod_cons_emulated_futex | |||
) |
TEST | ( | MPMCQueue | , |
mt_prod_cons_emulated_futex_dynamic | |||
) |
Definition at line 708 of file MPMCQueueTest.cpp.
References Atom, and runMtProdConsEmulatedFutex().
TEST | ( | MPMCQueue | , |
mt_never_fail | |||
) |
Definition at line 774 of file MPMCQueueTest.cpp.
TEST | ( | MPMCQueue | , |
mt_never_fail_emulated_futex | |||
) |
Definition at line 780 of file MPMCQueueTest.cpp.
TEST | ( | MPMCQueue | , |
mt_never_fail_deterministic | |||
) |
Definition at line 801 of file MPMCQueueTest.cpp.
References Atom, runMtNeverFailDeterministic(), and seed.
TEST | ( | MPMCQueue | , |
mt_never_fail_until_system | |||
) |
Definition at line 868 of file MPMCQueueTest.cpp.
References runMtNeverFailUntilSystem().
TEST | ( | MPMCQueue | , |
mt_never_fail_until_steady | |||
) |
Definition at line 885 of file MPMCQueueTest.cpp.
References runMtNeverFailUntilSteady().
TEST | ( | MPMCQueue | , |
perfect_forwarding | |||
) |
Definition at line 1047 of file MPMCQueueTest.cpp.
TEST | ( | MPMCQueue | , |
perfect_forwarding_relocatable | |||
) |
Definition at line 1051 of file MPMCQueueTest.cpp.
TEST | ( | MPMCQueue | , |
queue_moving | |||
) |
TEST | ( | MPMCQueue | , |
queue_moving_dynamic | |||
) |
Definition at line 1124 of file MPMCQueueTest.cpp.
TEST | ( | MPMCQueue | , |
explicit_zero_capacity_fail | |||
) |
Definition at line 1128 of file MPMCQueueTest.cpp.
References ASSERT_THROW.
TEST | ( | MPMCQueue | , |
try_read_until | |||
) |
Definition at line 1208 of file MPMCQueueTest.cpp.
TEST | ( | MPMCQueue | , |
try_read_until_dynamic | |||
) |
Definition at line 1212 of file MPMCQueueTest.cpp.
TEST | ( | MPMCQueue | , |
try_write_until | |||
) |
Definition at line 1216 of file MPMCQueueTest.cpp.
TEST | ( | MPMCQueue | , |
try_write_until_dynamic | |||
) |
Definition at line 1220 of file MPMCQueueTest.cpp.
TEST | ( | MPMCQueue | , |
try_write_until_timeout | |||
) |
Definition at line 1232 of file MPMCQueueTest.cpp.
TEST | ( | MPMCQueue | , |
must_fail_try_write_until_dynamic | |||
) |
Definition at line 1237 of file MPMCQueueTest.cpp.
void testTimeout | ( | MPMCQueue< int, std::atomic, Dynamic > & | q | ) |
void testTryReadUntil | ( | ) |
Definition at line 1136 of file MPMCQueueTest.cpp.
References b, folly::custom_stop_watch< Clock, Duration >::elapsed(), EXPECT_EQ, EXPECT_FALSE, EXPECT_TRUE, folly::custom_stop_watch< Clock, Duration >::getCheckpoint(), i, threads, and folly::detail::distributed_mutex::wait().
void testTryWriteUntil | ( | ) |
Definition at line 1171 of file MPMCQueueTest.cpp.
References b, folly::custom_stop_watch< Clock, Duration >::elapsed(), EXPECT_EQ, EXPECT_FALSE, EXPECT_TRUE, folly::custom_stop_watch< Clock, Duration >::getCheckpoint(), i, threads, folly::detail::distributed_mutex::wait(), and x.
|
static |
Definition at line 903 of file MPMCQueueTest.cpp.
Referenced by lc_outstanding(), lc_snap(), lc_step(), Lifecycle< R >::Lifecycle(), Lifecycle< R >::operator=(), and Lifecycle< R >::~Lifecycle().
|
static |
Definition at line 904 of file MPMCQueueTest.cpp.