proxygen
HazptrTest.cpp File Reference

Go to the source code of this file.

Classes

class  Count
 
class  Node< Atom >
 
class  NodeRC< Mutable, Atom >
 
struct  List< T, Atom >
 
class  NodeAuto< Atom >
 
class  HazptrPreInitTest
 

Typedefs

using DSched = folly::test::DeterministicSchedule
 

Functions

 DEFINE_bool (bench, false,"run benchmark")
 
 DEFINE_int64 (num_reps, 10,"Number of test reps")
 
 DEFINE_int32 (num_threads, 6,"Number of threads")
 
 DEFINE_int64 (num_ops, 1003,"Number of ops or pairs of ops per rep")
 
template<template< typename > class Atom = std::atomic>
void basic_objects_test ()
 
template<template< typename > class Atom = std::atomic>
void copy_and_move_test ()
 
template<template< typename > class Atom = std::atomic>
void basic_holders_test ()
 
template<template< typename > class Atom = std::atomic>
void basic_protection_test ()
 
template<template< typename > class Atom = std::atomic>
void virtual_test ()
 
template<template< typename > class Atom = std::atomic>
void destruction_test (hazptr_domain< Atom > &domain)
 
template<template< typename > class Atom = std::atomic>
void move_test ()
 
template<template< typename > class Atom = std::atomic>
void array_test ()
 
template<template< typename > class Atom = std::atomic>
void array_dtor_full_tc_test ()
 
template<template< typename > class Atom = std::atomic>
void local_test ()
 
template<bool Mutable, template< typename > class Atom = std::atomic>
void linked_test ()
 
template<bool Mutable, template< typename > class Atom = std::atomic>
void mt_linked_test ()
 
template<template< typename > class Atom = std::atomic>
void auto_retire_test ()
 
template<template< typename > class Atom = std::atomic>
void free_function_retire_test ()
 
template<template< typename > class Atom = std::atomic>
void cleanup_test ()
 
template<template< typename > class Atom = std::atomic>
void priv_dtor_test ()
 
template<template< typename > class Atom = std::atomic>
void lifo_test ()
 
template<template< typename > class Atom = std::atomic>
void swmr_test ()
 
template<template< typename > class Atom = std::atomic>
void wide_cas_test ()
 
 TEST (HazptrTest, basic_objects)
 
 TEST_F (HazptrPreInitTest, dsched_basic_objects)
 
 TEST (HazptrTest, copy_and_move)
 
 TEST_F (HazptrPreInitTest, dsched_copy_and_move)
 
 TEST (HazptrTest, basic_holders)
 
 TEST_F (HazptrPreInitTest, dsched_basic_holders)
 
 TEST (HazptrTest, basic_protection)
 
 TEST_F (HazptrPreInitTest, dsched_basic_protection)
 
 TEST (HazptrTest, virtual)
 
 TEST_F (HazptrPreInitTest, dsched_virtual)
 
 TEST (HazptrTest, destruction)
 
 TEST_F (HazptrPreInitTest, dsched_destruction)
 
 TEST (HazptrTest, move)
 
 TEST_F (HazptrPreInitTest, dsched_move)
 
 TEST (HazptrTest, array)
 
 TEST_F (HazptrPreInitTest, dsched_array)
 
 TEST (HazptrTest, array_dtor_full_tc)
 
 TEST_F (HazptrPreInitTest, dsched_array_dtor_full_tc)
 
 TEST (HazptrTest, local)
 
 TEST_F (HazptrPreInitTest, dsched_local)
 
 TEST (HazptrTest, linked_mutable)
 
 TEST_F (HazptrPreInitTest, dsched_linked_mutable)
 
 TEST (HazptrTest, linked_immutable)
 
 TEST_F (HazptrPreInitTest, dsched_linked_immutable)
 
 TEST (HazptrTest, mt_linked_mutable)
 
 TEST_F (HazptrPreInitTest, dsched_mt_linked_mutable)
 
 TEST (HazptrTest, mt_linked_immutable)
 
 TEST_F (HazptrPreInitTest, dsched_mt_linked_immutable)
 
 TEST (HazptrTest, auto_retire)
 
 TEST_F (HazptrPreInitTest, dsched_auto_retire)
 
 TEST (HazptrTest, free_function_retire)
 
 TEST_F (HazptrPreInitTest, dsched_free_function_retire)
 
 TEST (HazptrTest, cleanup)
 
 TEST_F (HazptrPreInitTest, dsched_cleanup)
 
 TEST (HazptrTest, priv_dtor)
 
 TEST_F (HazptrPreInitTest, dsched_priv_dtor)
 
 TEST (HazptrTest, lifo)
 
 TEST_F (HazptrPreInitTest, dsched_lifo)
 
 TEST (HazptrTest, swmr)
 
 TEST_F (HazptrPreInitTest, dsched_swmr)
 
 TEST (HazptrTest, wide_cas)
 
 TEST_F (HazptrPreInitTest, dsched_wide_cas)
 
 TEST (HazptrTest, reclamation_without_calling_cleanup)
 
template<typename InitFunc , typename Func , typename EndFunc >
uint64_t run_once (int nthreads, const InitFunc &init, const Func &fn, const EndFunc &endFn)
 
template<typename RepFunc >
uint64_t bench (std::string name, int ops, const RepFunc &repFn)
 
uint64_t holder_bench (std::string name, int nthreads)
 
template<size_t M>
uint64_t array_bench (std::string name, int nthreads)
 
template<size_t M>
uint64_t local_bench (std::string name, int nthreads)
 
uint64_t obj_bench (std::string name, int nthreads)
 
uint64_t list_hoh_bench (std::string name, int nthreads, int size, bool provided=false)
 
uint64_t list_protect_all_bench (std::string name, int nthreads, int size, bool provided=false)
 
uint64_t cleanup_bench (std::string name, int nthreads)
 
void benches ()
 
 TEST (HazptrTest, bench)
 

Variables

static Count c_
 
const int ops = 1000000
 
const int nthr [] = {1, 10}
 
const int sizes [] = {10, 20}
 

Typedef Documentation

Definition at line 52 of file HazptrTest.cpp.

Function Documentation

template<size_t M>
uint64_t array_bench ( std::string  name,
int  nthreads 
)
inline

Definition at line 1193 of file HazptrTest.cpp.

References a, bench(), bm::init(), nthreads, ops, and run_once().

1193  {
1194  auto repFn = [&] {
1195  auto init = [] {};
1196  auto fn = [&](int tid) {
1197  for (int j = tid; j < 10 * ops; j += nthreads) {
1199  }
1200  };
1201  auto endFn = [] {};
1202  return run_once(nthreads, init, fn, endFn);
1203  };
1204  return bench(name, ops, repFn);
1205 }
uint64_t bench(std::string name, int ops, const RepFunc &repFn)
uint64_t run_once(int nthreads, const InitFunc &init, const Func &fn, const EndFunc &endFn)
void init()
static int nthreads
const char * name
Definition: http_parser.c:437
char a
const int ops
template<template< typename > class Atom = std::atomic>
void array_dtor_full_tc_test ( )

Definition at line 456 of file HazptrTest.cpp.

References Atom, M, folly::gen::move, uint8_t, and x.

Referenced by TEST().

456  {
457 #if FOLLY_HAZPTR_THR_LOCAL
459 #else
460  const uint8_t M = 3;
461 #endif
462  {
463  // Fill the thread cache
465  }
466  {
467  // Empty array x
468  hazptr_array<M, Atom> x(nullptr);
469  {
470  // y ctor gets elements from the thread cache filled by w dtor.
472  // z ctor gets elements from the default domain.
474  // Elements of y are moved to x.
475  x = std::move(y);
476  // z dtor fills the thread cache.
477  }
478  // x dtor finds the thread cache full. It has to call
479  // ~hazptr_holder() for each of its elements, which were
480  // previously taken from the thread cache by y ctor.
481  }
482 }
Definition: InvokeTest.cpp:58
constexpr detail::Map< Move > move
Definition: Base-inl.h:2567
const int x
Definition: InvokeTest.cpp:72
**Optimized Holders **The template hazptr_array< M > provides most of the functionality *of M hazptr_holder s but with faster construction destruction *for M
Definition: Hazptr.h:104
Definition: InvokeTest.cpp:65
template<template< typename > class Atom = std::atomic>
void array_test ( )

Definition at line 436 of file HazptrTest.cpp.

References ASSERT_EQ, Atom, h, i, and folly::gen::move.

Referenced by TEST().

436  {
437  for (int i = 0; i < 100; ++i) {
438  auto x = new Node<Atom>(i);
440  // Protect object
441  hptr[2].reset(x);
442  // Empty array
443  hazptr_array<3, Atom> h(nullptr);
444  // Move assignment
445  h = std::move(hptr);
446  // Retire object
447  x->retire();
448  ASSERT_EQ(x->value(), i);
449  // Unprotect object - hptr2 is nonempty
450  h[2].reset();
451  }
452  hazptr_cleanup<Atom>();
453 }
Definition: InvokeTest.cpp:58
*than *hazptr_holder h
Definition: Hazptr.h:116
#define ASSERT_EQ(val1, val2)
Definition: gtest.h:1956
constexpr detail::Map< Move > move
Definition: Base-inl.h:2567
FOLLY_ALWAYS_INLINE void reset(const T *ptr) noexcept
Definition: HazptrHolder.h:153
template<template< typename > class Atom = std::atomic>
void auto_retire_test ( )

Definition at line 607 of file HazptrTest.cpp.

References a, folly::hazptr_obj_linked< Atom >::acquire_link_safe(), ASSERT_EQ, Atom, b, c, Count::clear(), Count::ctors(), Count::dtors(), and h.

Referenced by TEST().

607  {
608  c_.clear();
609  auto d = new NodeAuto<Atom>;
610  d->acquire_link_safe();
611  auto c = new NodeAuto<Atom>(d);
612  d->acquire_link_safe();
613  auto b = new NodeAuto<Atom>(d);
614  c->acquire_link_safe();
615  b->acquire_link_safe();
616  auto a = new NodeAuto<Atom>(b, c);
618  {
620  a->acquire_link_safe();
621  root().store(a);
622  ASSERT_EQ(c_.ctors(), 4);
623  /* So far the links and link counts are:
624  root-->a a-->b a-->c b-->d c-->d
625  a(1,0) b(1,0) c(1,0) d(2,0)
626  */
627  h.reset(c); /* h protects c */
628  hazptr_cleanup<Atom>();
629  ASSERT_EQ(c_.dtors(), 0);
630  /* Nothing is retired or reclaimed yet */
631  }
632  /* root dtor calls a->unlink, which calls a->release_link, which
633  changes a's link counts from (1,0) to (0,0), which triggers calls
634  to c->downgrade_link, b->downgrade_link, and a->retire.
635 
636  c->downgrade_link changes c's link counts from (1,0) to (0,1),
637  which triggers calls to d->downgrade_link and c->retire.
638 
639  d->downgrade_link changes d's link counts from (2,0) to (1,1).
640 
641  b->downgrade_link changes b's link counts from (1,0) to (0,1),
642  which triggers calls to d->downgrade_link and b->retire.
643 
644  d->downgrade_link changes d's link counts from (1,1) to (0,2),
645  which triggers a call to d->retire.
646 
647  So far (assuming retire-s did not trigger bulk_reclaim):
648  a-->b a-->c b-->d c-->d
649  a(0,0) b(0,1) c(0,1) d(0,2)
650  Retired: a b c d
651  Protected: c
652  */
653  hazptr_cleanup<Atom>();
654  /* hazptr_cleanup calls bulk_reclaim which finds a, b, and d
655  unprotected, which triggers calls to a->release_ref,
656  b->release_ref, and d->release_ref (not necessarily in that
657  order).
658 
659  a->release_ref finds a's link counts to be (0,0), which triggers
660  calls to c->release_ref, b->release_ref and delete a.
661 
662  The call to c->release_ref changes its link counts from (0,1) to
663  (0,0).
664 
665  The first call to b->release_ref changes b's link counts to
666  (0,0). The second call finds the link counts to be (0,0), which
667  triggers a call to d->release_ref and delete b.
668 
669  The first call to d->release_ref changes its link counts to
670  (0,1), and the second call changes them to (0,0);
671 
672  So far:
673  c-->d
674  a(deleted) b(deleted) c(0,0) d(0,0)
675  Retired and protected: c
676  bulk_reclamed-ed (i.e, found not protected): d
677  */
678  ASSERT_EQ(c_.dtors(), 2);
679  h.reset(); /* c is now no longer protected */
680  hazptr_cleanup<Atom>();
681  /* hazptr_cleanup calls bulk_reclaim which finds c unprotected,
682  which triggers a call to c->release_ref.
683 
684  c->release_ref finds c's link counts to be (0,0), which
685  triggers calls to d->release_ref and delete c.
686 
687  d->release_ref finds d's link counts to be (0,0), which triggers
688  a call to delete d.
689 
690  Finally:
691  a(deleted) b(deleted) c(deleted) d(deleted)
692  */
693  ASSERT_EQ(c_.dtors(), 4);
694 }
*than *hazptr_holder h
Definition: Hazptr.h:116
#define ASSERT_EQ(val1, val2)
Definition: gtest.h:1956
char b
static Count c_
Definition: HazptrTest.cpp:94
int ctors() const noexcept
Definition: HazptrTest.cpp:69
void clear() noexcept
Definition: HazptrTest.cpp:63
char a
int dtors() const noexcept
Definition: HazptrTest.cpp:73
void acquire_link_safe() noexcept
char c
template<template< typename > class Atom = std::atomic>
void basic_holders_test ( )

Definition at line 347 of file HazptrTest.cpp.

References Atom, and h.

Referenced by TEST().

347  {
351 }
*than *hazptr_holder h
Definition: Hazptr.h:116
template<template< typename > class Atom = std::atomic>
void basic_objects_test ( )

Definition at line 280 of file HazptrTest.cpp.

References folly::hazptr_obj_linked< Atom >::acquire_link_safe(), ASSERT_EQ, Atom, Count::clear(), Count::ctors(), Count::dtors(), folly::hazptr_obj_base< T, Atom, D >::retire(), and folly::hazptr_obj_base_linked< T, Atom, D >::retire().

Referenced by TEST().

280  {
281  c_.clear();
282  int num = 0;
283  {
284  ++num;
285  auto obj = new Node<Atom>;
286  obj->retire();
287  }
288  {
289  ++num;
290  auto obj = new NodeRC<false, Atom>(0, nullptr);
291  obj->retire();
292  }
293  {
294  ++num;
295  auto obj = new NodeRC<false, Atom>(0, nullptr);
296  obj->acquire_link_safe();
297  obj->unlink();
298  }
299  {
300  ++num;
301  auto obj = new NodeRC<false, Atom>(0, nullptr);
302  obj->acquire_link_safe();
303  obj->unlink_and_reclaim_unchecked();
304  }
305  {
306  ++num;
307  auto obj = new NodeRC<false, Atom>(0, nullptr);
308  obj->acquire_link_safe();
310  }
311  ASSERT_EQ(c_.ctors(), num);
312  hazptr_cleanup<Atom>();
313  ASSERT_EQ(c_.dtors(), num);
314 }
#define ASSERT_EQ(val1, val2)
Definition: gtest.h:1956
void retire(D deleter={}, hazptr_domain< Atom > &domain=default_hazptr_domain< Atom >())
Definition: HazptrObj.h:229
static Count c_
Definition: HazptrTest.cpp:94
int ctors() const noexcept
Definition: HazptrTest.cpp:69
void clear() noexcept
Definition: HazptrTest.cpp:63
int dtors() const noexcept
Definition: HazptrTest.cpp:73
void acquire_link_safe() noexcept
template<template< typename > class Atom = std::atomic>
void basic_protection_test ( )

Definition at line 354 of file HazptrTest.cpp.

References ASSERT_EQ, Atom, Count::clear(), Count::ctors(), Count::dtors(), h, and folly::hazptr_holder< Atom >::reset().

Referenced by TEST().

354  {
355  c_.clear();
356  auto obj = new Node<Atom>;
358  h.reset(obj);
359  obj->retire();
360  ASSERT_EQ(c_.ctors(), 1);
361  hazptr_cleanup<Atom>();
362  ASSERT_EQ(c_.dtors(), 0);
363  h.reset();
364  hazptr_cleanup<Atom>();
365  ASSERT_EQ(c_.dtors(), 1);
366 }
*than *hazptr_holder h
Definition: Hazptr.h:116
#define ASSERT_EQ(val1, val2)
Definition: gtest.h:1956
static Count c_
Definition: HazptrTest.cpp:94
int ctors() const noexcept
Definition: HazptrTest.cpp:69
void clear() noexcept
Definition: HazptrTest.cpp:63
int dtors() const noexcept
Definition: HazptrTest.cpp:73
FOLLY_ALWAYS_INLINE void reset(const T *ptr) noexcept
Definition: HazptrHolder.h:153
template<typename RepFunc >
uint64_t bench ( std::string  name,
int  ops,
const RepFunc &  repFn 
)

Definition at line 1147 of file HazptrTest.cpp.

References max, min, name, string, sum(), uint64_t, and folly::unit.

Referenced by array_bench(), cleanup_bench(), holder_bench(), list_hoh_bench(), list_protect_all_bench(), local_bench(), and obj_bench().

1147  {
1148  int reps = 10;
1149  uint64_t min = UINTMAX_MAX;
1150  uint64_t max = 0;
1151  uint64_t sum = 0;
1152 
1153  repFn(); // sometimes first run is outlier
1154  for (int r = 0; r < reps; ++r) {
1155  uint64_t dur = repFn();
1156  sum += dur;
1157  min = std::min(min, dur);
1158  max = std::max(max, dur);
1159  }
1160 
1161  const std::string unit = " ns";
1162  uint64_t avg = sum / reps;
1163  uint64_t res = min;
1164  std::cout << name;
1165  std::cout << " " << std::setw(4) << max / ops << unit;
1166  std::cout << " " << std::setw(4) << avg / ops << unit;
1167  std::cout << " " << std::setw(4) << res / ops << unit;
1168  std::cout << std::endl;
1169  return res;
1170 }
std::atomic< int64_t > sum(0)
LogLevel max
Definition: LogLevel.cpp:31
const char * name
Definition: http_parser.c:437
LogLevel min
Definition: LogLevel.cpp:30
constexpr Unit unit
Definition: Unit.h:45
const int ops
const char * string
Definition: Conv.cpp:212
void benches ( )

Definition at line 1308 of file HazptrTest.cpp.

References cleanup_bench(), holder_bench(), i, list_hoh_bench(), list_protect_all_bench(), nthr, obj_bench(), and sizes.

Referenced by TEST().

1308  {
1309  for (int i : nthr) {
1310  std::cout << "================================ " << std::setw(2) << i
1311  << " threads "
1312  << "================================" << std::endl;
1313  std::cout << "10x construct/destruct hazptr_holder ";
1314  holder_bench("", i);
1315  std::cout << "10x construct/destruct hazptr_array<1> ";
1316  array_bench<1>("", i);
1317  std::cout << "10x construct/destruct hazptr_array<2> ";
1318  array_bench<2>("", i);
1319  std::cout << "10x construct/destruct hazptr_array<3> ";
1320  array_bench<3>("", i);
1321  std::cout << "10x construct/destruct hazptr_local<1> ";
1322  local_bench<1>("", i);
1323  std::cout << "10x construct/destruct hazptr_local<2> ";
1324  local_bench<2>("", i);
1325  std::cout << "10x construct/destruct hazptr_local<3> ";
1326  local_bench<3>("", i);
1327  std::cout << "allocate/retire/reclaim object ";
1328  obj_bench("", i);
1329  for (int j : sizes) {
1330  std::cout << j << "-item list hand-over-hand - own hazptrs ";
1331  list_hoh_bench("", i, j, true);
1332  std::cout << j << "-item list hand-over-hand ";
1333  list_hoh_bench("", i, j);
1334  std::cout << j << "-item list protect all - own hazptr ";
1335  list_protect_all_bench("", i, j, true);
1336  std::cout << j << "-item list protect all ";
1337  list_protect_all_bench("", i, j);
1338  }
1339  std::cout << "hazptr_cleanup ";
1340  cleanup_bench("", i);
1341  }
1342 }
uint64_t holder_bench(std::string name, int nthreads)
uint64_t cleanup_bench(std::string name, int nthreads)
uint64_t obj_bench(std::string name, int nthreads)
const int nthr[]
const int sizes[]
uint64_t list_protect_all_bench(std::string name, int nthreads, int size, bool provided=false)
uint64_t list_hoh_bench(std::string name, int nthreads, int size, bool provided=false)
uint64_t cleanup_bench ( std::string  name,
int  nthreads 
)

Definition at line 1290 of file HazptrTest.cpp.

References bench(), folly::hazptr_cleanup(), i, bm::init(), ops, and run_once().

Referenced by benches().

1290  {
1291  auto repFn = [&] {
1292  auto init = [] {};
1293  auto fn = [&](int) {
1295  for (int i = 0; i < 1000; i++) {
1296  hazptr_cleanup();
1297  }
1298  };
1299  auto endFn = [] {};
1300  return run_once(nthreads, init, fn, endFn);
1301  };
1302  return bench(name, ops, repFn);
1303 }
uint64_t bench(std::string name, int ops, const RepFunc &repFn)
uint64_t run_once(int nthreads, const InitFunc &init, const Func &fn, const EndFunc &endFn)
void init()
static int nthreads
const char * name
Definition: http_parser.c:437
void hazptr_cleanup(hazptr_domain< Atom > &domain=default_hazptr_domain< Atom >()) noexcept
Definition: HazptrDomain.h:384
const int ops
template<template< typename > class Atom = std::atomic>
void cleanup_test ( )

Definition at line 720 of file HazptrTest.cpp.

References ASSERT_EQ, Atom, Count::clear(), Count::ctors(), Count::dtors(), h, i, folly::test::DeterministicSchedule::join(), folly::hazptr_obj_base< T, Atom, D >::retire(), folly::pushmi::detail::t, folly::test::DeterministicSchedule::thread(), and threads.

Referenced by TEST().

720  {
721  int threadOps = 1007;
722  int mainOps = 19;
723  c_.clear();
724  Atom<int> threadsDone{0};
725  Atom<bool> mainDone{false};
726  std::vector<std::thread> threads(FLAGS_num_threads);
727  for (int tid = 0; tid < FLAGS_num_threads; ++tid) {
728  threads[tid] = DSched::thread([&, tid]() {
729  for (int j = tid; j < threadOps; j += FLAGS_num_threads) {
730  auto p = new Node<Atom>;
731  p->retire();
732  }
733  threadsDone.fetch_add(1);
734  while (!mainDone.load()) {
735  /* spin */;
736  }
737  });
738  }
739  { // include the main thread in the test
740  for (int i = 0; i < mainOps; ++i) {
741  auto p = new Node<Atom>;
742  p->retire();
743  }
744  }
745  while (threadsDone.load() < FLAGS_num_threads) {
746  /* spin */;
747  }
748  ASSERT_EQ(c_.ctors(), threadOps + mainOps);
749  hazptr_cleanup<Atom>();
750  ASSERT_EQ(c_.dtors(), threadOps + mainOps);
751  mainDone.store(true);
752  for (auto& t : threads) {
753  DSched::join(t);
754  }
755  { // Cleanup after using array
756  c_.clear();
758  {
760  auto p0 = new Node<Atom>;
761  auto p1 = new Node<Atom>;
762  h[0].reset(p0);
763  h[1].reset(p1);
764  p0->retire();
765  p1->retire();
766  }
767  ASSERT_EQ(c_.ctors(), 2);
768  hazptr_cleanup<Atom>();
769  ASSERT_EQ(c_.dtors(), 2);
770  }
771  { // Cleanup after using local
772  c_.clear();
774  {
776  auto p0 = new Node<Atom>;
777  auto p1 = new Node<Atom>;
778  h[0].reset(p0);
779  h[1].reset(p1);
780  p0->retire();
781  p1->retire();
782  }
783  ASSERT_EQ(c_.ctors(), 2);
784  hazptr_cleanup<Atom>();
785  ASSERT_EQ(c_.dtors(), 2);
786  }
787 }
*than *hazptr_holder h
Definition: Hazptr.h:116
#define ASSERT_EQ(val1, val2)
Definition: gtest.h:1956
void retire(D deleter={}, hazptr_domain< Atom > &domain=default_hazptr_domain< Atom >())
Definition: HazptrObj.h:229
static std::thread thread(Func &&func, Args &&...args)
static Count c_
Definition: HazptrTest.cpp:94
int ctors() const noexcept
Definition: HazptrTest.cpp:69
void clear() noexcept
Definition: HazptrTest.cpp:63
std::vector< std::thread::id > threads
int dtors() const noexcept
Definition: HazptrTest.cpp:73
static void join(std::thread &child)
template<template< typename > class Atom = std::atomic>
void copy_and_move_test ( )

Definition at line 317 of file HazptrTest.cpp.

References a, Atom, and folly::gen::move.

Referenced by TEST().

317  {
318  struct Obj : hazptr_obj_base<Obj, Atom> {
319  int a;
320  };
321 
322  auto p1 = new Obj();
323  auto p2 = new Obj(*p1);
324  p1->retire();
325  p2->retire();
326 
327  p1 = new Obj();
328  p2 = new Obj(std::move(*p1));
329  p1->retire();
330  p2->retire();
331 
332  p1 = new Obj();
333  p2 = new Obj();
334  *p2 = *p1;
335  p1->retire();
336  p2->retire();
337 
338  p1 = new Obj();
339  p2 = new Obj();
340  *p2 = std::move(*p1);
341  p1->retire();
342  p2->retire();
343  hazptr_cleanup<Atom>();
344 }
constexpr detail::Map< Move > move
Definition: Base-inl.h:2567
char a
DEFINE_bool ( bench  ,
false  ,
"run benchmark  
)
DEFINE_int32 ( num_threads  ,
,
"Number of threads  
)
DEFINE_int64 ( num_reps  ,
10  ,
"Number of test reps"   
)
DEFINE_int64 ( num_ops  ,
1003  ,
"Number of ops or pairs of ops per rep"   
)
template<template< typename > class Atom = std::atomic>
void destruction_test ( hazptr_domain< Atom > &  domain)

Definition at line 387 of file HazptrTest.cpp.

References Atom, i, cpp.ast::next(), and val.

Referenced by TEST().

387  {
388  struct Thing : public hazptr_obj_base<Thing, Atom> {
389  Thing* next;
390  hazptr_domain<Atom>* domain;
391  int val;
392  Thing(int v, Thing* n, hazptr_domain<Atom>* d)
393  : next(n), domain(d), val(v) {}
394  ~Thing() {
395  if (next) {
396  next->retire(*domain);
397  }
398  }
399  };
400  Thing* last{nullptr};
401  for (int i = 0; i < 2000; i++) {
402  last = new Thing(i, last, &domain);
403  }
404  last->retire(domain);
405  hazptr_cleanup<Atom>();
406 }
double val
Definition: String.cpp:273
hazptr_obj< Atom > * next() const noexcept
Definition: HazptrObj.h:86
template<template< typename > class Atom = std::atomic>
void free_function_retire_test ( )

Definition at line 697 of file HazptrTest.cpp.

References ASSERT_TRUE, Atom, testing::gmock_matchers_test::foo, foo2(), and folly::hazptr_domain< Atom >::retire().

Referenced by TEST().

697  {
698  auto foo = new int;
699  hazptr_retire<Atom>(foo);
700  auto foo2 = new int;
701  hazptr_retire<Atom>(foo2, [](int* obj) { delete obj; });
702 
703  bool retired = false;
704  {
705  hazptr_domain<Atom> myDomain0;
706  struct delret {
707  bool* retired_;
708  explicit delret(bool* retire) : retired_(retire) {}
709  ~delret() {
710  *retired_ = true;
711  }
712  };
713  auto foo3 = new delret(&retired);
714  myDomain0.retire(foo3);
715  }
716  ASSERT_TRUE(retired);
717 }
FOLLY_NOINLINE void foo2()
void retire(T *obj, D reclaim={})
Definition: HazptrDomain.h:87
#define ASSERT_TRUE(condition)
Definition: gtest.h:1865
uint64_t holder_bench ( std::string  name,
int  nthreads 
)
inline

Definition at line 1178 of file HazptrTest.cpp.

References bench(), h, bm::init(), nthreads, ops, and run_once().

Referenced by benches().

1178  {
1179  auto repFn = [&] {
1180  auto init = [] {};
1181  auto fn = [&](int tid) {
1182  for (int j = tid; j < 10 * ops; j += nthreads) {
1184  }
1185  };
1186  auto endFn = [] {};
1187  return run_once(nthreads, init, fn, endFn);
1188  };
1189  return bench(name, ops, repFn);
1190 }
uint64_t bench(std::string name, int ops, const RepFunc &repFn)
*than *hazptr_holder h
Definition: Hazptr.h:116
uint64_t run_once(int nthreads, const InitFunc &init, const Func &fn, const EndFunc &endFn)
void init()
static int nthreads
const char * name
Definition: http_parser.c:437
const int ops
template<template< typename > class Atom = std::atomic>
void lifo_test ( )

Definition at line 813 of file HazptrTest.cpp.

References ASSERT_EQ, ASSERT_TRUE, Atom, i, folly::test::DeterministicSchedule::join(), folly::fibers::local(), folly::HazptrLockFreeLIFO< T, Atom >::pop(), folly::HazptrLockFreeLIFO< T, Atom >::push(), s, sum(), folly::pushmi::detail::t, folly::test::DeterministicSchedule::thread(), threads, and v.

Referenced by TEST().

813  {
814  for (int i = 0; i < FLAGS_num_reps; ++i) {
815  Atom<int> sum{0};
817  std::vector<std::thread> threads(FLAGS_num_threads);
818  for (int tid = 0; tid < FLAGS_num_threads; ++tid) {
819  threads[tid] = DSched::thread([&, tid]() {
820  int local = 0;
821  for (int j = tid; j < FLAGS_num_ops; j += FLAGS_num_threads) {
822  s.push(j);
823  int v;
824  ASSERT_TRUE(s.pop(v));
825  local += v;
826  }
827  sum.fetch_add(local);
828  });
829  }
830  for (auto& t : threads) {
831  DSched::join(t);
832  }
833  hazptr_cleanup<Atom>();
834  int expected = FLAGS_num_ops * (FLAGS_num_ops - 1) / 2;
835  ASSERT_EQ(sum.load(), expected);
836  }
837 }
std::atomic< int64_t > sum(0)
auto v
#define ASSERT_EQ(val1, val2)
Definition: gtest.h:1956
static std::thread thread(Func &&func, Args &&...args)
std::vector< std::thread::id > threads
static set< string > s
static void join(std::thread &child)
#define ASSERT_TRUE(condition)
Definition: gtest.h:1865
template<bool Mutable, template< typename > class Atom = std::atomic>
void linked_test ( )

Definition at line 500 of file HazptrTest.cpp.

References ASSERT_EQ, ASSERT_GT, Atom, Count::clear(), Count::ctors(), Count::dtors(), i, folly::gen::Mutable, NodeRC< Mutable, Atom >::next(), folly::hazptr_obj_base_linked< NodeRC< Mutable, Atom >, Atom >::retire(), and v.

500  {
501  c_.clear();
502  NodeRC<Mutable, Atom>* p = nullptr;
503  int num = 193;
504  for (int i = 0; i < num - 1; ++i) {
505  p = new NodeRC<Mutable, Atom>(i, p, true);
506  }
507  p = new NodeRC<Mutable, Atom>(num - 1, p, Mutable);
508  hazptr_holder<Atom> hptr;
509  hptr.reset(p);
510  if (!Mutable) {
511  for (auto q = p->next(); q; q = q->next()) {
512  q->retire();
513  }
514  }
515  int v = num;
516  for (auto q = p; q; q = q->next()) {
517  ASSERT_GT(v, 0);
518  --v;
519  ASSERT_EQ(q->value(), v);
520  }
521 
522  hazptr_cleanup<Atom>();
523  ASSERT_EQ(c_.ctors(), num);
524  ASSERT_EQ(c_.dtors(), 0);
525 
526  if (Mutable) {
528  } else {
529  p->retire();
530  }
531  hazptr_cleanup<Atom>();
532  ASSERT_EQ(c_.dtors(), 0);
533 
534  hptr.reset();
535  hazptr_cleanup<Atom>();
536  ASSERT_EQ(c_.dtors(), num);
537 }
#define ASSERT_GT(val1, val2)
Definition: gtest.h:1976
auto v
#define ASSERT_EQ(val1, val2)
Definition: gtest.h:1956
NodeRC< Mutable, Atom > * next() const noexcept
Definition: HazptrTest.cpp:153
static Count c_
Definition: HazptrTest.cpp:94
int ctors() const noexcept
Definition: HazptrTest.cpp:69
void clear() noexcept
Definition: HazptrTest.cpp:63
#define Atom
int dtors() const noexcept
Definition: HazptrTest.cpp:73
uint64_t list_hoh_bench ( std::string  name,
int  nthreads,
int  size,
bool  provided = false 
)

Definition at line 1238 of file HazptrTest.cpp.

References bench(), List< T, Atom >::hand_over_hand(), bm::init(), nthreads, ops, and run_once().

Referenced by benches().

1242  {
1243  auto repFn = [&] {
1244  List<Node<>> l(size);
1245  auto init = [&] {};
1246  auto fn = [&](int tid) {
1247  if (provided) {
1248  hazptr_local<2> hptr;
1249  for (int j = tid; j < ops; j += nthreads) {
1250  l.hand_over_hand(size, &hptr[0], &hptr[1]);
1251  }
1252  } else {
1253  for (int j = tid; j < ops; j += nthreads) {
1254  l.hand_over_hand(size);
1255  }
1256  }
1257  };
1258  auto endFn = [] {};
1259  return run_once(nthreads, init, fn, endFn);
1260  };
1261  return bench(name, ops, repFn);
1262 }
uint64_t bench(std::string name, int ops, const RepFunc &repFn)
uint64_t run_once(int nthreads, const InitFunc &init, const Func &fn, const EndFunc &endFn)
void init()
static int nthreads
const char * name
Definition: http_parser.c:437
constexpr auto size(C const &c) -> decltype(c.size())
Definition: Access.h:45
const int ops
uint64_t list_protect_all_bench ( std::string  name,
int  nthreads,
int  size,
bool  provided = false 
)

Definition at line 1264 of file HazptrTest.cpp.

References bench(), bm::init(), nthreads, ops, List< T, Atom >::protect_all(), and run_once().

Referenced by benches().

1268  {
1269  auto repFn = [&] {
1270  List<NodeRC<true>> l(size);
1271  auto init = [] {};
1272  auto fn = [&](int tid) {
1273  if (provided) {
1274  hazptr_local<1> hptr;
1275  for (int j = tid; j < ops; j += nthreads) {
1276  l.protect_all(size, hptr[0]);
1277  }
1278  } else {
1279  for (int j = tid; j < ops; j += nthreads) {
1280  l.protect_all(size);
1281  }
1282  }
1283  };
1284  auto endFn = [] {};
1285  return run_once(nthreads, init, fn, endFn);
1286  };
1287  return bench(name, ops, repFn);
1288 }
uint64_t bench(std::string name, int ops, const RepFunc &repFn)
uint64_t run_once(int nthreads, const InitFunc &init, const Func &fn, const EndFunc &endFn)
void init()
static int nthreads
const char * name
Definition: http_parser.c:437
constexpr auto size(C const &c) -> decltype(c.size())
Definition: Access.h:45
const int ops
template<size_t M>
uint64_t local_bench ( std::string  name,
int  nthreads 
)
inline

Definition at line 1208 of file HazptrTest.cpp.

References a, bench(), bm::init(), nthreads, ops, and run_once().

1208  {
1209  auto repFn = [&] {
1210  auto init = [] {};
1211  auto fn = [&](int tid) {
1212  for (int j = tid; j < 10 * ops; j += nthreads) {
1214  }
1215  };
1216  auto endFn = [] {};
1217  return run_once(nthreads, init, fn, endFn);
1218  };
1219  return bench(name, ops, repFn);
1220 }
uint64_t bench(std::string name, int ops, const RepFunc &repFn)
uint64_t run_once(int nthreads, const InitFunc &init, const Func &fn, const EndFunc &endFn)
void init()
static int nthreads
const char * name
Definition: http_parser.c:437
char a
const int ops
template<template< typename > class Atom = std::atomic>
void local_test ( )

Definition at line 485 of file HazptrTest.cpp.

References Atom, and i.

Referenced by TEST().

485  {
486  for (int i = 0; i < 100; ++i) {
487  auto x = new Node<Atom>(i);
489  // Protect object
490  hptr[2].reset(x);
491  // Retire object
492  x->retire();
493  // Unprotect object - hptr2 is nonempty
494  hptr[2].reset();
495  }
496  hazptr_cleanup<Atom>();
497 }
Definition: InvokeTest.cpp:58
template<template< typename > class Atom = std::atomic>
void move_test ( )

Definition at line 409 of file HazptrTest.cpp.

References ASSERT_EQ, Atom, i, folly::gen::move, and folly::hazptr_holder< Atom >::reset().

Referenced by TEST().

409  {
410  for (int i = 0; i < 100; ++i) {
411  auto x = new Node<Atom>(i);
412  hazptr_holder<Atom> hptr0;
413  // Protect object
414  hptr0.reset(x);
415  // Retire object
416  x->retire();
417  // Move constructor - still protected
418  hazptr_holder<Atom> hptr1(std::move(hptr0));
419  // Self move is no-op - still protected
420  auto phptr1 = &hptr1;
421  ASSERT_EQ(phptr1, &hptr1);
422  hptr1 = std::move(*phptr1);
423  // Empty constructor
424  hazptr_holder<Atom> hptr2(nullptr);
425  // Move assignment - still protected
426  hptr2 = std::move(hptr1);
427  // Access object
428  ASSERT_EQ(x->value(), i);
429  // Unprotect object - hptr2 is nonempty
430  hptr2.reset();
431  }
432  hazptr_cleanup<Atom>();
433 }
Definition: InvokeTest.cpp:58
#define ASSERT_EQ(val1, val2)
Definition: gtest.h:1956
constexpr detail::Map< Move > move
Definition: Base-inl.h:2567
template<bool Mutable, template< typename > class Atom = std::atomic>
void mt_linked_test ( )

Definition at line 540 of file HazptrTest.cpp.

References ASSERT_EQ, ASSERT_GT, Atom, Count::clear(), Count::ctors(), Count::dtors(), folly::hazptr_holder< Atom >::get_protected(), i, folly::test::DeterministicSchedule::join(), folly::gen::Mutable, NodeRC< Mutable, Atom >::next(), nthr, folly::pushmi::detail::t, folly::test::DeterministicSchedule::thread(), folly::hazptr_obj_base_linked< NodeRC< Mutable, Atom >, Atom >::unlink(), and v.

540  {
541  c_.clear();
542 
543  Atom<bool> ready(false);
544  Atom<bool> done(false);
545  Atom<int> setHazptrs(0);
547 
548  int num = FLAGS_num_ops;
549  int nthr = FLAGS_num_threads;
550  ASSERT_GT(FLAGS_num_threads, 0);
551  std::vector<std::thread> thr(nthr);
552  for (int i = 0; i < nthr; ++i) {
553  thr[i] = DSched::thread([&] {
554  while (!ready.load()) {
555  /* spin */
556  }
557  hazptr_holder<Atom> hptr;
558  auto p = hptr.get_protected(head());
559  ++setHazptrs;
560  /* Concurrent with removal */
561  int v = num;
562  for (auto q = p; q; q = q->next()) {
563  ASSERT_GT(v, 0);
564  --v;
565  ASSERT_EQ(q->value(), v);
566  }
567  ASSERT_EQ(v, 0);
568  while (!done.load()) {
569  /* spin */
570  }
571  });
572  }
573 
574  NodeRC<Mutable, Atom>* p = nullptr;
575  for (int i = 0; i < num - 1; ++i) {
576  p = new NodeRC<Mutable, Atom>(i, p, true);
577  }
578  p = new NodeRC<Mutable, Atom>(num - 1, p, Mutable);
579  ASSERT_EQ(c_.ctors(), num);
580  head().store(p);
581  ready.store(true);
582  while (setHazptrs.load() < nthr) {
583  /* spin */
584  }
585 
586  /* this is concurrent with traversal by readers */
587  head().store(nullptr);
588  if (Mutable) {
589  p->unlink();
590  } else {
591  for (auto q = p; q; q = q->next()) {
592  q->retire();
593  }
594  }
595  ASSERT_EQ(c_.dtors(), 0);
596  done.store(true);
597 
598  for (auto& t : thr) {
599  DSched::join(t);
600  }
601 
602  hazptr_cleanup<Atom>();
603  ASSERT_EQ(c_.dtors(), num);
604 }
#define ASSERT_GT(val1, val2)
Definition: gtest.h:1976
auto v
#define ASSERT_EQ(val1, val2)
Definition: gtest.h:1956
FOLLY_ALWAYS_INLINE T * get_protected(const Atom< T * > &src) noexcept
Definition: HazptrHolder.h:138
const int nthr[]
static std::thread thread(Func &&func, Args &&...args)
NodeRC< Mutable, Atom > * next() const noexcept
Definition: HazptrTest.cpp:153
static Count c_
Definition: HazptrTest.cpp:94
int ctors() const noexcept
Definition: HazptrTest.cpp:69
void clear() noexcept
Definition: HazptrTest.cpp:63
#define Atom
int dtors() const noexcept
Definition: HazptrTest.cpp:73
static void join(std::thread &child)
uint64_t obj_bench ( std::string  name,
int  nthreads 
)
inline

Definition at line 1222 of file HazptrTest.cpp.

References bench(), bm::init(), nthreads, ops, and run_once().

Referenced by benches().

1222  {
1223  struct Foo : public hazptr_obj_base<Foo> {};
1224  auto repFn = [&] {
1225  auto init = [] {};
1226  auto fn = [&](int tid) {
1227  for (int j = tid; j < ops; j += nthreads) {
1228  auto p = new Foo;
1229  p->retire();
1230  }
1231  };
1232  auto endFn = [] {};
1233  return run_once(nthreads, init, fn, endFn);
1234  };
1235  return bench(name, ops, repFn);
1236 }
uint64_t bench(std::string name, int ops, const RepFunc &repFn)
Foo(std::atomic< int > &d)
uint64_t run_once(int nthreads, const InitFunc &init, const Func &fn, const EndFunc &endFn)
void init()
static int nthreads
const char * name
Definition: http_parser.c:437
const int ops
template<template< typename > class Atom = std::atomic>
void priv_dtor_test ( )

Definition at line 790 of file HazptrTest.cpp.

References ASSERT_EQ, Atom, Count::clear(), Count::ctors(), Count::dtors(), folly::test::DeterministicSchedule::join(), and folly::test::DeterministicSchedule::thread().

Referenced by TEST().

790  {
791  c_.clear();
792  using NodeT = NodeRC<true, Atom>;
793  auto y = new NodeT;
794  y->acquire_link_safe();
795  struct Foo : hazptr_obj_base<Foo, Atom> {
797  };
798  auto x = new Foo;
799  x->r_().store(y);
800  /* Thread retires x. Dtor of TLS priv list pushes x to domain, which
801  triggers bulk reclaim due to timed cleanup (when the test is run
802  by itself). Reclamation of x unlinks and retires y. y should
803  not be pushed into the thread's priv list. It should be pushed to
804  domain instead. */
805  auto thr = DSched::thread([&]() { x->retire(); });
806  DSched::join(thr);
807  ASSERT_EQ(c_.ctors(), 1);
808  hazptr_cleanup<Atom>();
809  ASSERT_EQ(c_.dtors(), 1);
810 }
Definition: InvokeTest.cpp:58
Foo(std::atomic< int > &d)
#define ASSERT_EQ(val1, val2)
Definition: gtest.h:1956
static std::thread thread(Func &&func, Args &&...args)
static Count c_
Definition: HazptrTest.cpp:94
int ctors() const noexcept
Definition: HazptrTest.cpp:69
void clear() noexcept
Definition: HazptrTest.cpp:63
int dtors() const noexcept
Definition: HazptrTest.cpp:73
Definition: InvokeTest.cpp:65
static void join(std::thread &child)
template<typename InitFunc , typename Func , typename EndFunc >
uint64_t run_once ( int  nthreads,
const InitFunc &  init,
const Func &  fn,
const EndFunc &  endFn 
)

Definition at line 1116 of file HazptrTest.cpp.

References b, count, folly::hazptr_cleanup(), bm::init(), now(), nthreads, start, folly::pushmi::detail::t, threads, and folly::test::Barrier::wait().

Referenced by array_bench(), cleanup_bench(), holder_bench(), list_hoh_bench(), list_protect_all_bench(), local_bench(), and obj_bench().

1120  {
1121  std::atomic<bool> start{false};
1122  Barrier b(nthreads + 1);
1123  init();
1124  std::vector<std::thread> threads(nthreads);
1125  for (int tid = 0; tid < nthreads; ++tid) {
1126  threads[tid] = std::thread([&, tid] {
1127  b.wait();
1128  fn(tid);
1129  });
1130  }
1131  b.wait();
1132  // begin time measurement
1133  auto tbegin = std::chrono::steady_clock::now();
1134  start.store(true);
1135  for (auto& t : threads) {
1136  t.join();
1137  }
1138  hazptr_cleanup();
1139  // end time measurement
1140  auto tend = std::chrono::steady_clock::now();
1141  endFn();
1142  return std::chrono::duration_cast<std::chrono::nanoseconds>(tend - tbegin)
1143  .count();
1144 }
char b
std::chrono::steady_clock::time_point now()
void init()
std::vector< std::thread::id > threads
static int nthreads
void hazptr_cleanup(hazptr_domain< Atom > &domain=default_hazptr_domain< Atom >()) noexcept
Definition: HazptrDomain.h:384
auto start
int * count
template<template< typename > class Atom = std::atomic>
void swmr_test ( )

Definition at line 840 of file HazptrTest.cpp.

References folly::HazptrSWMRSet< T, Atom >::add(), Atom, folly::HazptrSWMRSet< T, Atom >::contains(), i, folly::test::DeterministicSchedule::join(), folly::HazptrSWMRSet< T, Atom >::remove(), s, folly::pushmi::detail::t, T, folly::test::DeterministicSchedule::thread(), threads, and uint64_t.

Referenced by TEST().

840  {
841  using T = uint64_t;
842  for (int i = 0; i < FLAGS_num_reps; ++i) {
844  std::vector<std::thread> threads(FLAGS_num_threads);
845  for (int tid = 0; tid < FLAGS_num_threads; ++tid) {
846  threads[tid] = DSched::thread([&s, tid]() {
847  for (int j = tid; j < FLAGS_num_ops; j += FLAGS_num_threads) {
848  s.contains(j);
849  }
850  });
851  }
852  for (int j = 0; j < 10; ++j) {
853  s.add(j);
854  }
855  for (int j = 0; j < 10; ++j) {
856  s.remove(j);
857  }
858  for (auto& t : threads) {
859  DSched::join(t);
860  }
861  hazptr_cleanup<Atom>();
862  }
863 }
#define T(v)
Definition: http_parser.c:233
static std::thread thread(Func &&func, Args &&...args)
std::vector< std::thread::id > threads
bool contains(const T &val) const
Definition: HazptrSWMRSet.h:88
bool remove(const T &v)
Definition: HazptrSWMRSet.h:71
static set< string > s
static void join(std::thread &child)
TEST ( HazptrTest  ,
basic_objects   
)

Definition at line 896 of file HazptrTest.cpp.

References basic_objects_test().

896  {
898 }
void basic_objects_test()
Definition: HazptrTest.cpp:280
TEST ( HazptrTest  ,
copy_and_move   
)

Definition at line 905 of file HazptrTest.cpp.

References copy_and_move_test().

905  {
907 }
void copy_and_move_test()
Definition: HazptrTest.cpp:317
TEST ( HazptrTest  ,
basic_holders   
)

Definition at line 914 of file HazptrTest.cpp.

References basic_holders_test().

914  {
916 }
void basic_holders_test()
Definition: HazptrTest.cpp:347
TEST ( HazptrTest  ,
basic_protection   
)

Definition at line 923 of file HazptrTest.cpp.

References basic_protection_test().

923  {
925 }
void basic_protection_test()
Definition: HazptrTest.cpp:354
TEST ( HazptrTest  ,
virtual   
)

Definition at line 932 of file HazptrTest.cpp.

References virtual_test().

932  {
933  virtual_test();
934 }
void virtual_test()
Definition: HazptrTest.cpp:369
TEST ( HazptrTest  ,
destruction   
)

Definition at line 941 of file HazptrTest.cpp.

References destruction_test().

941  {
942  {
943  hazptr_domain<> myDomain0;
944  destruction_test(myDomain0);
945  }
946  destruction_test(default_hazptr_domain<std::atomic>());
947 }
void destruction_test(hazptr_domain< Atom > &domain)
Definition: HazptrTest.cpp:387
TEST ( HazptrTest  ,
move   
)

Definition at line 959 of file HazptrTest.cpp.

References move_test().

959  {
960  move_test();
961 }
void move_test()
Definition: HazptrTest.cpp:409
TEST ( HazptrTest  ,
array   
)

Definition at line 968 of file HazptrTest.cpp.

References array_test().

968  {
969  array_test();
970 }
void array_test()
Definition: HazptrTest.cpp:436
TEST ( HazptrTest  ,
array_dtor_full_tc   
)

Definition at line 977 of file HazptrTest.cpp.

References array_dtor_full_tc_test().

977  {
979 }
void array_dtor_full_tc_test()
Definition: HazptrTest.cpp:456
TEST ( HazptrTest  ,
local   
)

Definition at line 986 of file HazptrTest.cpp.

References local_test().

986  {
987  local_test();
988 }
void local_test()
Definition: HazptrTest.cpp:485
TEST ( HazptrTest  ,
linked_mutable   
)

Definition at line 995 of file HazptrTest.cpp.

995  {
996  linked_test<true>();
997 }
TEST ( HazptrTest  ,
linked_immutable   
)

Definition at line 1004 of file HazptrTest.cpp.

1004  {
1005  linked_test<false>();
1006 }
TEST ( HazptrTest  ,
mt_linked_mutable   
)

Definition at line 1013 of file HazptrTest.cpp.

1013  {
1014  mt_linked_test<true>();
1015 }
TEST ( HazptrTest  ,
mt_linked_immutable   
)

Definition at line 1022 of file HazptrTest.cpp.

1022  {
1023  mt_linked_test<false>();
1024 }
TEST ( HazptrTest  ,
auto_retire   
)

Definition at line 1031 of file HazptrTest.cpp.

References auto_retire_test().

1031  {
1032  auto_retire_test();
1033 }
void auto_retire_test()
Definition: HazptrTest.cpp:607
TEST ( HazptrTest  ,
free_function_retire   
)

Definition at line 1040 of file HazptrTest.cpp.

References free_function_retire_test().

1040  {
1042 }
void free_function_retire_test()
Definition: HazptrTest.cpp:697
TEST ( HazptrTest  ,
cleanup   
)

Definition at line 1049 of file HazptrTest.cpp.

References cleanup_test().

1049  {
1050  cleanup_test();
1051 }
void cleanup_test()
Definition: HazptrTest.cpp:720
TEST ( HazptrTest  ,
priv_dtor   
)

Definition at line 1058 of file HazptrTest.cpp.

References priv_dtor_test().

1058  {
1059  priv_dtor_test();
1060 }
void priv_dtor_test()
Definition: HazptrTest.cpp:790
TEST ( HazptrTest  ,
lifo   
)

Definition at line 1067 of file HazptrTest.cpp.

References lifo_test().

1067  {
1068  lifo_test();
1069 }
void lifo_test()
Definition: HazptrTest.cpp:813
TEST ( HazptrTest  ,
swmr   
)

Definition at line 1076 of file HazptrTest.cpp.

References swmr_test().

1076  {
1077  swmr_test();
1078 }
void swmr_test()
Definition: HazptrTest.cpp:840
TEST ( HazptrTest  ,
wide_cas   
)

Definition at line 1085 of file HazptrTest.cpp.

References wide_cas_test().

1085  {
1086  wide_cas_test();
1087 }
void wide_cas_test()
Definition: HazptrTest.cpp:866
TEST ( HazptrTest  ,
reclamation_without_calling_cleanup   
)

Definition at line 1094 of file HazptrTest.cpp.

References ASSERT_GT, Count::clear(), Count::dtors(), folly::detail::hazptr_domain_rcount_threshold(), i, nthr, folly::hazptr_obj_base< T, Atom, D >::retire(), and folly::pushmi::detail::t.

1094  {
1095  c_.clear();
1096  int nthr = 5;
1098  std::vector<std::thread> thr(nthr);
1099  for (int tid = 0; tid < nthr; ++tid) {
1100  thr[tid] = std::thread([&, tid] {
1101  for (int i = tid; i < objs; i += nthr) {
1102  auto p = new Node<>;
1103  p->retire();
1104  }
1105  });
1106  }
1107  for (auto& t : thr) {
1108  t.join();
1109  }
1110  ASSERT_GT(c_.dtors(), 0);
1111 }
#define ASSERT_GT(val1, val2)
Definition: gtest.h:1976
void retire(D deleter={}, hazptr_domain< Atom > &domain=default_hazptr_domain< Atom >())
Definition: HazptrObj.h:229
const int nthr[]
static Count c_
Definition: HazptrTest.cpp:94
void clear() noexcept
Definition: HazptrTest.cpp:63
constexpr int hazptr_domain_rcount_threshold()
Definition: HazptrDomain.h:38
int dtors() const noexcept
Definition: HazptrTest.cpp:73
TEST ( HazptrTest  ,
bench   
)

Definition at line 1344 of file HazptrTest.cpp.

References benches().

1344  {
1345  if (FLAGS_bench) {
1346  benches();
1347  }
1348 }
void benches()
TEST_F ( HazptrPreInitTest  ,
dsched_basic_objects   
)

Definition at line 900 of file HazptrTest.cpp.

References folly::test::DeterministicSchedule::uniform().

900  {
901  DSched sched(DSched::uniform(0));
902  basic_objects_test<DeterministicAtomic>();
903 }
static std::function< size_t(size_t)> uniform(uint64_t seed)
TEST_F ( HazptrPreInitTest  ,
dsched_copy_and_move   
)

Definition at line 909 of file HazptrTest.cpp.

References folly::test::DeterministicSchedule::uniform().

909  {
910  DSched sched(DSched::uniform(0));
911  copy_and_move_test<DeterministicAtomic>();
912 }
static std::function< size_t(size_t)> uniform(uint64_t seed)
TEST_F ( HazptrPreInitTest  ,
dsched_basic_holders   
)

Definition at line 918 of file HazptrTest.cpp.

References folly::test::DeterministicSchedule::uniform().

918  {
919  DSched sched(DSched::uniform(0));
920  basic_holders_test<DeterministicAtomic>();
921 }
static std::function< size_t(size_t)> uniform(uint64_t seed)
TEST_F ( HazptrPreInitTest  ,
dsched_basic_protection   
)

Definition at line 927 of file HazptrTest.cpp.

References folly::test::DeterministicSchedule::uniform().

927  {
928  DSched sched(DSched::uniform(0));
929  basic_protection_test<DeterministicAtomic>();
930 }
static std::function< size_t(size_t)> uniform(uint64_t seed)
TEST_F ( HazptrPreInitTest  ,
dsched_virtual   
)

Definition at line 936 of file HazptrTest.cpp.

References folly::test::DeterministicSchedule::uniform().

936  {
937  DSched sched(DSched::uniform(0));
938  virtual_test<DeterministicAtomic>();
939 }
static std::function< size_t(size_t)> uniform(uint64_t seed)
TEST_F ( HazptrPreInitTest  ,
dsched_destruction   
)

Definition at line 949 of file HazptrTest.cpp.

References folly::test::DeterministicSchedule::uniform().

949  {
950  DSched sched(DSched::uniform(0));
951  {
953  destruction_test<DeterministicAtomic>(myDomain0);
954  }
955  destruction_test<DeterministicAtomic>(
956  default_hazptr_domain<DeterministicAtomic>());
957 }
static std::function< size_t(size_t)> uniform(uint64_t seed)
TEST_F ( HazptrPreInitTest  ,
dsched_move   
)

Definition at line 963 of file HazptrTest.cpp.

References folly::test::DeterministicSchedule::uniform().

963  {
964  DSched sched(DSched::uniform(0));
965  move_test<DeterministicAtomic>();
966 }
static std::function< size_t(size_t)> uniform(uint64_t seed)
TEST_F ( HazptrPreInitTest  ,
dsched_array   
)

Definition at line 972 of file HazptrTest.cpp.

References folly::test::DeterministicSchedule::uniform().

972  {
973  DSched sched(DSched::uniform(0));
974  array_test<DeterministicAtomic>();
975 }
static std::function< size_t(size_t)> uniform(uint64_t seed)
TEST_F ( HazptrPreInitTest  ,
dsched_array_dtor_full_tc   
)

Definition at line 981 of file HazptrTest.cpp.

References folly::test::DeterministicSchedule::uniform().

981  {
982  DSched sched(DSched::uniform(0));
983  array_dtor_full_tc_test<DeterministicAtomic>();
984 }
static std::function< size_t(size_t)> uniform(uint64_t seed)
TEST_F ( HazptrPreInitTest  ,
dsched_local   
)

Definition at line 990 of file HazptrTest.cpp.

References folly::test::DeterministicSchedule::uniform().

990  {
991  DSched sched(DSched::uniform(0));
992  local_test<DeterministicAtomic>();
993 }
static std::function< size_t(size_t)> uniform(uint64_t seed)
TEST_F ( HazptrPreInitTest  ,
dsched_linked_mutable   
)

Definition at line 999 of file HazptrTest.cpp.

References folly::test::DeterministicSchedule::uniform().

999  {
1000  DSched sched(DSched::uniform(0));
1001  linked_test<true, DeterministicAtomic>();
1002 }
static std::function< size_t(size_t)> uniform(uint64_t seed)
TEST_F ( HazptrPreInitTest  ,
dsched_linked_immutable   
)

Definition at line 1008 of file HazptrTest.cpp.

References folly::test::DeterministicSchedule::uniform().

1008  {
1009  DSched sched(DSched::uniform(0));
1010  linked_test<false, DeterministicAtomic>();
1011 }
static std::function< size_t(size_t)> uniform(uint64_t seed)
TEST_F ( HazptrPreInitTest  ,
dsched_mt_linked_mutable   
)

Definition at line 1017 of file HazptrTest.cpp.

References folly::test::DeterministicSchedule::uniform().

1017  {
1018  DSched sched(DSched::uniform(0));
1019  mt_linked_test<true, DeterministicAtomic>();
1020 }
static std::function< size_t(size_t)> uniform(uint64_t seed)
TEST_F ( HazptrPreInitTest  ,
dsched_mt_linked_immutable   
)

Definition at line 1026 of file HazptrTest.cpp.

References folly::test::DeterministicSchedule::uniform().

1026  {
1027  DSched sched(DSched::uniform(0));
1028  mt_linked_test<false, DeterministicAtomic>();
1029 }
static std::function< size_t(size_t)> uniform(uint64_t seed)
TEST_F ( HazptrPreInitTest  ,
dsched_auto_retire   
)

Definition at line 1035 of file HazptrTest.cpp.

References folly::test::DeterministicSchedule::uniform().

1035  {
1036  DSched sched(DSched::uniform(0));
1037  auto_retire_test<DeterministicAtomic>();
1038 }
static std::function< size_t(size_t)> uniform(uint64_t seed)
TEST_F ( HazptrPreInitTest  ,
dsched_free_function_retire   
)

Definition at line 1044 of file HazptrTest.cpp.

References folly::test::DeterministicSchedule::uniform().

1044  {
1045  DSched sched(DSched::uniform(0));
1046  free_function_retire_test<DeterministicAtomic>();
1047 }
static std::function< size_t(size_t)> uniform(uint64_t seed)
TEST_F ( HazptrPreInitTest  ,
dsched_cleanup   
)

Definition at line 1053 of file HazptrTest.cpp.

References folly::test::DeterministicSchedule::uniform().

1053  {
1054  DSched sched(DSched::uniform(0));
1055  cleanup_test<DeterministicAtomic>();
1056 }
static std::function< size_t(size_t)> uniform(uint64_t seed)
TEST_F ( HazptrPreInitTest  ,
dsched_priv_dtor   
)

Definition at line 1062 of file HazptrTest.cpp.

References folly::test::DeterministicSchedule::uniform().

1062  {
1063  DSched sched(DSched::uniform(0));
1064  priv_dtor_test<DeterministicAtomic>();
1065 }
static std::function< size_t(size_t)> uniform(uint64_t seed)
TEST_F ( HazptrPreInitTest  ,
dsched_lifo   
)

Definition at line 1071 of file HazptrTest.cpp.

References folly::test::DeterministicSchedule::uniform().

1071  {
1072  DSched sched(DSched::uniform(0));
1073  lifo_test<DeterministicAtomic>();
1074 }
static std::function< size_t(size_t)> uniform(uint64_t seed)
TEST_F ( HazptrPreInitTest  ,
dsched_swmr   
)

Definition at line 1080 of file HazptrTest.cpp.

References folly::test::DeterministicSchedule::uniform().

1080  {
1081  DSched sched(DSched::uniform(0));
1082  swmr_test<DeterministicAtomic>();
1083 }
static std::function< size_t(size_t)> uniform(uint64_t seed)
TEST_F ( HazptrPreInitTest  ,
dsched_wide_cas   
)

Definition at line 1089 of file HazptrTest.cpp.

References folly::test::DeterministicSchedule::uniform().

1089  {
1090  DSched sched(DSched::uniform(0));
1091  wide_cas_test<DeterministicAtomic>();
1092 }
static std::function< size_t(size_t)> uniform(uint64_t seed)
template<template< typename > class Atom = std::atomic>
void virtual_test ( )

Definition at line 369 of file HazptrTest.cpp.

References a, ASSERT_EQ, Atom, i, and folly::hazptr_holder< Atom >::reset().

Referenced by TEST().

369  {
370  struct Thing : public hazptr_obj_base<Thing, Atom> {
371  virtual ~Thing() {}
372  int a;
373  };
374  for (int i = 0; i < 100; i++) {
375  auto bar = new Thing;
376  bar->a = i;
377 
378  hazptr_holder<Atom> hptr;
379  hptr.reset(bar);
380  bar->retire();
381  ASSERT_EQ(bar->a, i);
382  }
383  hazptr_cleanup<Atom>();
384 }
#define ASSERT_EQ(val1, val2)
Definition: gtest.h:1956
char a
FOLLY_ALWAYS_INLINE void reset(const T *ptr) noexcept
Definition: HazptrHolder.h:153
template<template< typename > class Atom = std::atomic>
void wide_cas_test ( )

Definition at line 866 of file HazptrTest.cpp.

References ASSERT_FALSE, ASSERT_TRUE, folly::HazptrWideCAS< T, Atom >::cas(), s, and string.

Referenced by TEST().

866  {
868  std::string u = "";
869  std::string v = "11112222";
870  auto ret = s.cas(u, v);
871  ASSERT_TRUE(ret);
872  u = "";
873  v = "11112222";
874  ret = s.cas(u, v);
875  ASSERT_FALSE(ret);
876  u = "11112222";
877  v = "22223333";
878  ret = s.cas(u, v);
879  ASSERT_TRUE(ret);
880  u = "22223333";
881  v = "333344445555";
882  ret = s.cas(u, v);
883  ASSERT_TRUE(ret);
884  hazptr_cleanup<Atom>();
885 }
bool cas(T &u, T &v)
Definition: HazptrWideCAS.h:42
const char * string
Definition: Conv.cpp:212
static set< string > s
#define ASSERT_FALSE(condition)
Definition: gtest.h:1868
#define ASSERT_TRUE(condition)
Definition: gtest.h:1865

Variable Documentation

const int nthr[] = {1, 10}

Definition at line 1305 of file HazptrTest.cpp.

Referenced by benches(), mt_linked_test(), and TEST().

const int sizes[] = {10, 20}