Hazptr-fwd.h 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169
  1. /*
  2. * Copyright 2018-present Facebook, Inc.
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * You may obtain a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. */
  16. #pragma once
  17. #include <atomic>
  18. #include <memory>
  19. ///
  20. /// Forward declatations and implicit documentation of all hazptr
  21. /// top-level classes, functions, macros, default values, and globals.
  22. ///
  23. /** FOLYY_HAZPTR_THR_LOCAL */
  24. #if FOLLY_MOBILE
  25. #define FOLLY_HAZPTR_THR_LOCAL false
  26. #else
  27. #define FOLLY_HAZPTR_THR_LOCAL true
  28. #endif
  29. namespace folly {
  30. ///
  31. /// Hazard pointer record.
  32. /// Defined in HazptrRec.h
  33. ///
  34. /** hazptr_rec */
  35. template <template <typename> class Atom = std::atomic>
  36. class hazptr_rec;
  37. ///
  38. /// Classes related to objects protected by hazard pointers.
  39. /// Defined in HazptrObj.h
  40. ///
  41. /** hazptr_obj */
  42. template <template <typename> class Atom = std::atomic>
  43. class hazptr_obj;
  44. /** hazptr_obj_list */
  45. template <template <typename> class Atom = std::atomic>
  46. class hazptr_obj_list;
  47. /** hazptr_deleter */
  48. template <typename T, typename D>
  49. class hazptr_deleter;
  50. /** hazptr_obj_base */
  51. template <
  52. typename T,
  53. template <typename> class Atom = std::atomic,
  54. typename D = std::default_delete<T>>
  55. class hazptr_obj_base;
  56. ///
  57. /// Classes related to link counted objects and automatic retirement.
  58. /// Defined in HazptrLinked.h
  59. ///
  60. /** hazptr_root */
  61. template <typename T, template <typename> class Atom = std::atomic>
  62. class hazptr_root;
  63. /** hazptr_obj_linked */
  64. template <template <typename> class Atom = std::atomic>
  65. class hazptr_obj_linked;
  66. /** hazptr_obj_base_linked */
  67. template <
  68. typename T,
  69. template <typename> class Atom = std::atomic,
  70. typename Deleter = std::default_delete<T>>
  71. class hazptr_obj_base_linked;
  72. ///
  73. /// Classes and functions related to thread local structures.
  74. /// Defined in HazptrThrLocal.h
  75. ///
  76. /** hazptr_tc_entry */
  77. template <template <typename> class Atom = std::atomic>
  78. class hazptr_tc_entry;
  79. /** hazptr_tc */
  80. template <template <typename> class Atom = std::atomic>
  81. class hazptr_tc;
  82. /** hazptr_tc_tls */
  83. template <template <typename> class Atom = std::atomic>
  84. hazptr_tc<Atom>& hazptr_tc_tls();
  85. /** hazptr_priv */
  86. template <template <typename> class Atom = std::atomic>
  87. class hazptr_priv;
  88. /** hazptr_priv_tls */
  89. template <template <typename> class Atom = std::atomic>
  90. hazptr_priv<Atom>& hazptr_priv_tls();
  91. ///
  92. /// Hazard pointer domain
  93. /// Defined in HazptrDomain.h
  94. ///
  95. /** hazptr_domain */
  96. template <template <typename> class Atom = std::atomic>
  97. class hazptr_domain;
  98. /** default_hazptr_domain */
  99. template <template <typename> class Atom = std::atomic>
  100. hazptr_domain<Atom>& default_hazptr_domain();
  101. /** hazptr_domain_push_retired */
  102. template <template <typename> class Atom = std::atomic>
  103. void hazptr_domain_push_retired(
  104. hazptr_obj_list<Atom>& l,
  105. bool check = true,
  106. hazptr_domain<Atom>& domain = default_hazptr_domain<Atom>()) noexcept;
  107. /** hazptr_retire */
  108. template <
  109. template <typename> class Atom = std::atomic,
  110. typename T,
  111. typename D = std::default_delete<T>>
  112. void hazptr_retire(T* obj, D reclaim = {});
  113. /** hazptr_cleanup */
  114. template <template <typename> class Atom = std::atomic>
  115. void hazptr_cleanup(
  116. hazptr_domain<Atom>& domain = default_hazptr_domain<Atom>()) noexcept;
  117. /** Global default domain defined in Hazptr.cpp */
  118. extern hazptr_domain<std::atomic> default_domain;
  119. ///
  120. /// Classes related to hazard pointer holders.
  121. /// Defined in HazptrHolder.h
  122. ///
  123. /** hazptr_holder */
  124. template <template <typename> class Atom = std::atomic>
  125. class hazptr_holder;
  126. /** Free function swap of hazptr_holder-s */
  127. template <template <typename> class Atom = std::atomic>
  128. void swap(hazptr_holder<Atom>&, hazptr_holder<Atom>&) noexcept;
  129. /** hazptr_array */
  130. template <uint8_t M = 1, template <typename> class Atom = std::atomic>
  131. class hazptr_array;
  132. /** hazptr_local */
  133. template <uint8_t M = 1, template <typename> class Atom = std::atomic>
  134. class hazptr_local;
  135. } // namespace folly