Commit 8a278994 authored by Lee Howes's avatar Lee Howes Committed by Facebook Github Bot

Rename hazptr DEBUG_PRINT macro to HAZPTR_DEBUG_PRINT to avoid name clashes...

Rename hazptr DEBUG_PRINT macro to HAZPTR_DEBUG_PRINT to avoid name clashes with other uses in code.

Reviewed By: yfeldblum, magedm

Differential Revision: D6863117

fbshipit-source-id: 1626eacafbdddcfdaf181b2a5d0f6e216425b1ff
parent 20260a99
...@@ -21,7 +21,7 @@ ...@@ -21,7 +21,7 @@
#define HAZPTR_DEBUG false #define HAZPTR_DEBUG false
#endif #endif
#define DEBUG_PRINT(...) \ #define HAZPTR_DEBUG_PRINT(...) \
do { \ do { \
if (HAZPTR_DEBUG) { \ if (HAZPTR_DEBUG) { \
VLOG(2) << __func__ << " --- " << __VA_ARGS__; \ VLOG(2) << __func__ << " --- " << __VA_ARGS__; \
......
...@@ -27,11 +27,11 @@ class LockFreeLIFO { ...@@ -27,11 +27,11 @@ class LockFreeLIFO {
friend LockFreeLIFO; friend LockFreeLIFO;
public: public:
~Node() { ~Node() {
DEBUG_PRINT(this); HAZPTR_DEBUG_PRINT(this);
} }
private: private:
Node(T v, Node* n) : value_(v), next_(n) { Node(T v, Node* n) : value_(v), next_(n) {
DEBUG_PRINT(this); HAZPTR_DEBUG_PRINT(this);
} }
T value_; T value_;
Node* next_; Node* next_;
...@@ -39,15 +39,15 @@ class LockFreeLIFO { ...@@ -39,15 +39,15 @@ class LockFreeLIFO {
public: public:
LockFreeLIFO() { LockFreeLIFO() {
DEBUG_PRINT(this); HAZPTR_DEBUG_PRINT(this);
} }
~LockFreeLIFO() { ~LockFreeLIFO() {
DEBUG_PRINT(this); HAZPTR_DEBUG_PRINT(this);
} }
void push(T val) { void push(T val) {
DEBUG_PRINT(this); HAZPTR_DEBUG_PRINT(this);
auto pnode = new Node(val, head_.load()); auto pnode = new Node(val, head_.load());
while (!head_.compare_exchange_weak(pnode->next_, pnode)) { while (!head_.compare_exchange_weak(pnode->next_, pnode)) {
; ;
...@@ -55,7 +55,7 @@ class LockFreeLIFO { ...@@ -55,7 +55,7 @@ class LockFreeLIFO {
} }
bool pop(T& val) { bool pop(T& val) {
DEBUG_PRINT(this); HAZPTR_DEBUG_PRINT(this);
hazptr_holder hptr; hazptr_holder hptr;
Node* pnode = head_.load(); Node* pnode = head_.load();
do { do {
......
...@@ -65,11 +65,11 @@ class MWMRListSet { ...@@ -65,11 +65,11 @@ class MWMRListSet {
public: public:
explicit Node(T e) : elem_(e) { explicit Node(T e) : elem_(e) {
DEBUG_PRINT(this << " " << e); HAZPTR_DEBUG_PRINT(this << " " << e);
} }
~Node() { ~Node() {
DEBUG_PRINT(this); HAZPTR_DEBUG_PRINT(this);
auto next = getPtr(next_.load(std::memory_order_relaxed)); auto next = getPtr(next_.load(std::memory_order_relaxed));
if (next) { if (next) {
next->release(); next->release();
......
...@@ -32,7 +32,7 @@ class SWMRListSet { ...@@ -32,7 +32,7 @@ class SWMRListSet {
template <typename Node> template <typename Node>
struct Reclaimer { struct Reclaimer {
void operator()(Node* p) { void operator()(Node* p) {
DEBUG_PRINT(p << " " << sizeof(Node)); HAZPTR_DEBUG_PRINT(p << " " << sizeof(Node));
delete p; delete p;
} }
}; };
...@@ -43,12 +43,12 @@ class SWMRListSet { ...@@ -43,12 +43,12 @@ class SWMRListSet {
std::atomic<Node*> next_; std::atomic<Node*> next_;
Node(T e, Node* n) : elem_(e), next_(n) { Node(T e, Node* n) : elem_(e), next_(n) {
DEBUG_PRINT(this << " " << e << " " << n); HAZPTR_DEBUG_PRINT(this << " " << e << " " << n);
} }
public: public:
~Node() { ~Node() {
DEBUG_PRINT(this); HAZPTR_DEBUG_PRINT(this);
} }
}; };
......
...@@ -30,10 +30,17 @@ class WideCAS { ...@@ -30,10 +30,17 @@ class WideCAS {
class Node : public hazptr_obj_base<Node> { class Node : public hazptr_obj_base<Node> {
friend WideCAS; friend WideCAS;
T val_; T val_;
Node() : val_(T()) { DEBUG_PRINT(this << " " << val_); } Node() : val_(T()) {
explicit Node(T v) : val_(v) { DEBUG_PRINT(this << " " << v); } HAZPTR_DEBUG_PRINT(this << " " << val_);
}
explicit Node(T v) : val_(v) {
HAZPTR_DEBUG_PRINT(this << " " << v);
}
public: public:
~Node() { DEBUG_PRINT(this); } ~Node() {
HAZPTR_DEBUG_PRINT(this);
}
}; };
std::atomic<Node*> p_ = {new Node()}; std::atomic<Node*> p_ = {new Node()};
...@@ -41,12 +48,12 @@ class WideCAS { ...@@ -41,12 +48,12 @@ class WideCAS {
public: public:
WideCAS() = default; WideCAS() = default;
~WideCAS() { ~WideCAS() {
DEBUG_PRINT(this << " " << p_.load()); HAZPTR_DEBUG_PRINT(this << " " << p_.load());
delete p_.load(); delete p_.load();
} }
bool cas(T& u, T& v) { bool cas(T& u, T& v) {
DEBUG_PRINT(this << " " << u << " " << v); HAZPTR_DEBUG_PRINT(this << " " << u << " " << v);
Node* n = new Node(v); Node* n = new Node(v);
hazptr_holder hptr; hazptr_holder hptr;
Node* p; Node* p;
...@@ -59,7 +66,7 @@ class WideCAS { ...@@ -59,7 +66,7 @@ class WideCAS {
} while (true); } while (true);
hptr.reset(); hptr.reset();
p->retire(); p->retire();
DEBUG_PRINT(this << " " << p << " " << u << " " << n << " " << v); HAZPTR_DEBUG_PRINT(this << " " << p << " " << u << " " << n << " " << v);
return true; return true;
} }
}; };
......
...@@ -220,7 +220,7 @@ inline constexpr hazptr_domain::hazptr_domain(memory_resource* mr) noexcept ...@@ -220,7 +220,7 @@ inline constexpr hazptr_domain::hazptr_domain(memory_resource* mr) noexcept
template <typename T, typename D> template <typename T, typename D>
inline void hazptr_obj_base<T, D>::retire(hazptr_domain& domain, D deleter) { inline void hazptr_obj_base<T, D>::retire(hazptr_domain& domain, D deleter) {
DEBUG_PRINT(this << " " << &domain); HAZPTR_DEBUG_PRINT(this << " " << &domain);
retireCheck(); retireCheck();
deleter_ = std::move(deleter); deleter_ = std::move(deleter);
reclaim_ = [](hazptr_obj* p) { reclaim_ = [](hazptr_obj* p) {
...@@ -245,7 +245,7 @@ template <typename T, typename D> ...@@ -245,7 +245,7 @@ template <typename T, typename D>
inline void hazptr_obj_base_refcounted<T, D>::retire( inline void hazptr_obj_base_refcounted<T, D>::retire(
hazptr_domain& domain, hazptr_domain& domain,
D deleter) { D deleter) {
DEBUG_PRINT(this << " " << &domain); HAZPTR_DEBUG_PRINT(this << " " << &domain);
preRetire(deleter); preRetire(deleter);
if (HAZPTR_PRIV && if (HAZPTR_PRIV &&
(HAZPTR_ONE_DOMAIN || (&domain == &default_hazptr_domain()))) { (HAZPTR_ONE_DOMAIN || (&domain == &default_hazptr_domain()))) {
...@@ -258,14 +258,14 @@ inline void hazptr_obj_base_refcounted<T, D>::retire( ...@@ -258,14 +258,14 @@ inline void hazptr_obj_base_refcounted<T, D>::retire(
template <typename T, typename D> template <typename T, typename D>
inline void hazptr_obj_base_refcounted<T, D>::acquire_ref() { inline void hazptr_obj_base_refcounted<T, D>::acquire_ref() {
DEBUG_PRINT(this); HAZPTR_DEBUG_PRINT(this);
auto oldval = refcount_.fetch_add(1); auto oldval = refcount_.fetch_add(1);
DCHECK(oldval >= 0); DCHECK(oldval >= 0);
} }
template <typename T, typename D> template <typename T, typename D>
inline void hazptr_obj_base_refcounted<T, D>::acquire_ref_safe() { inline void hazptr_obj_base_refcounted<T, D>::acquire_ref_safe() {
DEBUG_PRINT(this); HAZPTR_DEBUG_PRINT(this);
auto oldval = refcount_.load(std::memory_order_acquire); auto oldval = refcount_.load(std::memory_order_acquire);
DCHECK(oldval >= 0); DCHECK(oldval >= 0);
refcount_.store(oldval + 1, std::memory_order_release); refcount_.store(oldval + 1, std::memory_order_release);
...@@ -273,7 +273,7 @@ inline void hazptr_obj_base_refcounted<T, D>::acquire_ref_safe() { ...@@ -273,7 +273,7 @@ inline void hazptr_obj_base_refcounted<T, D>::acquire_ref_safe() {
template <typename T, typename D> template <typename T, typename D>
inline bool hazptr_obj_base_refcounted<T, D>::release_ref() { inline bool hazptr_obj_base_refcounted<T, D>::release_ref() {
DEBUG_PRINT(this); HAZPTR_DEBUG_PRINT(this);
auto oldval = refcount_.load(std::memory_order_acquire); auto oldval = refcount_.load(std::memory_order_acquire);
if (oldval > 0) { if (oldval > 0) {
oldval = refcount_.fetch_sub(1); oldval = refcount_.fetch_sub(1);
...@@ -282,7 +282,7 @@ inline bool hazptr_obj_base_refcounted<T, D>::release_ref() { ...@@ -282,7 +282,7 @@ inline bool hazptr_obj_base_refcounted<T, D>::release_ref() {
refcount_.store(-1); refcount_.store(-1);
} }
} }
DEBUG_PRINT(this << " " << oldval); HAZPTR_DEBUG_PRINT(this << " " << oldval);
DCHECK(oldval >= 0); DCHECK(oldval >= 0);
return oldval == 0; return oldval == 0;
} }
...@@ -333,23 +333,23 @@ FOLLY_ALWAYS_INLINE hazptr_holder::hazptr_holder(hazptr_domain& domain) { ...@@ -333,23 +333,23 @@ FOLLY_ALWAYS_INLINE hazptr_holder::hazptr_holder(hazptr_domain& domain) {
auto hprec = hazptr_tc_try_get(); auto hprec = hazptr_tc_try_get();
if (LIKELY(hprec != nullptr)) { if (LIKELY(hprec != nullptr)) {
hazptr_ = hprec; hazptr_ = hprec;
DEBUG_PRINT(this << " " << domain_ << " " << hazptr_); HAZPTR_DEBUG_PRINT(this << " " << domain_ << " " << hazptr_);
return; return;
} }
} }
hazptr_ = domain_->hazptrAcquire(); hazptr_ = domain_->hazptrAcquire();
DEBUG_PRINT(this << " " << domain_ << " " << hazptr_); HAZPTR_DEBUG_PRINT(this << " " << domain_ << " " << hazptr_);
if (hazptr_ == nullptr) { std::bad_alloc e; throw e; } if (hazptr_ == nullptr) { std::bad_alloc e; throw e; }
} }
FOLLY_ALWAYS_INLINE hazptr_holder::hazptr_holder(std::nullptr_t) noexcept { FOLLY_ALWAYS_INLINE hazptr_holder::hazptr_holder(std::nullptr_t) noexcept {
domain_ = nullptr; domain_ = nullptr;
hazptr_ = nullptr; hazptr_ = nullptr;
DEBUG_PRINT(this << " " << domain_ << " " << hazptr_); HAZPTR_DEBUG_PRINT(this << " " << domain_ << " " << hazptr_);
} }
FOLLY_ALWAYS_INLINE hazptr_holder::~hazptr_holder() { FOLLY_ALWAYS_INLINE hazptr_holder::~hazptr_holder() {
DEBUG_PRINT(this); HAZPTR_DEBUG_PRINT(this);
if (LIKELY(hazptr_ != nullptr)) { if (LIKELY(hazptr_ != nullptr)) {
hazptr_->clear(); hazptr_->clear();
if (LIKELY( if (LIKELY(
...@@ -392,7 +392,7 @@ FOLLY_ALWAYS_INLINE bool hazptr_holder::try_protect( ...@@ -392,7 +392,7 @@ FOLLY_ALWAYS_INLINE bool hazptr_holder::try_protect(
T*& ptr, T*& ptr,
const std::atomic<T*>& src, const std::atomic<T*>& src,
Func f) noexcept { Func f) noexcept {
DEBUG_PRINT(this << " " << ptr << " " << &src); HAZPTR_DEBUG_PRINT(this << " " << ptr << " " << &src);
reset(f(ptr)); reset(f(ptr));
/*** Full fence ***/ hazptr_mb::light(); /*** Full fence ***/ hazptr_mb::light();
T* p = src.load(std::memory_order_acquire); T* p = src.load(std::memory_order_acquire);
...@@ -417,28 +417,28 @@ FOLLY_ALWAYS_INLINE T* hazptr_holder::get_protected( ...@@ -417,28 +417,28 @@ FOLLY_ALWAYS_INLINE T* hazptr_holder::get_protected(
T* p = src.load(std::memory_order_relaxed); T* p = src.load(std::memory_order_relaxed);
while (!try_protect(p, src, f)) { while (!try_protect(p, src, f)) {
} }
DEBUG_PRINT(this << " " << p << " " << &src); HAZPTR_DEBUG_PRINT(this << " " << p << " " << &src);
return p; return p;
} }
template <typename T> template <typename T>
FOLLY_ALWAYS_INLINE void hazptr_holder::reset(const T* ptr) noexcept { FOLLY_ALWAYS_INLINE void hazptr_holder::reset(const T* ptr) noexcept {
auto p = static_cast<hazptr_obj*>(const_cast<T*>(ptr)); auto p = static_cast<hazptr_obj*>(const_cast<T*>(ptr));
DEBUG_PRINT(this << " " << ptr << " p:" << p); HAZPTR_DEBUG_PRINT(this << " " << ptr << " p:" << p);
DCHECK(hazptr_); // UB if *this is empty DCHECK(hazptr_); // UB if *this is empty
hazptr_->set(p); hazptr_->set(p);
} }
FOLLY_ALWAYS_INLINE void hazptr_holder::reset(std::nullptr_t) noexcept { FOLLY_ALWAYS_INLINE void hazptr_holder::reset(std::nullptr_t) noexcept {
DEBUG_PRINT(this); HAZPTR_DEBUG_PRINT(this);
DCHECK(hazptr_); // UB if *this is empty DCHECK(hazptr_); // UB if *this is empty
hazptr_->clear(); hazptr_->clear();
} }
FOLLY_ALWAYS_INLINE void hazptr_holder::swap(hazptr_holder& rhs) noexcept { FOLLY_ALWAYS_INLINE void hazptr_holder::swap(hazptr_holder& rhs) noexcept {
DEBUG_PRINT( HAZPTR_DEBUG_PRINT(
this << " " << this->hazptr_ << " " << this->domain_ << " -- " this << " " << this->hazptr_ << " " << this->domain_ << " -- " << &rhs
<< &rhs << " " << rhs.hazptr_ << " " << rhs.domain_); << " " << rhs.hazptr_ << " " << rhs.domain_);
if (!HAZPTR_ONE_DOMAIN) { if (!HAZPTR_ONE_DOMAIN) {
std::swap(this->domain_, rhs.domain_); std::swap(this->domain_, rhs.domain_);
} }
...@@ -466,10 +466,10 @@ FOLLY_ALWAYS_INLINE hazptr_array<M>::hazptr_array() { ...@@ -466,10 +466,10 @@ FOLLY_ALWAYS_INLINE hazptr_array<M>::hazptr_array() {
for (size_t i = 0; i < M; ++i) { for (size_t i = 0; i < M; ++i) {
auto hprec = tc[offset + i].hprec_; auto hprec = tc[offset + i].hprec_;
DCHECK(hprec != nullptr); DCHECK(hprec != nullptr);
DEBUG_PRINT(i << " " << &h[i]); HAZPTR_DEBUG_PRINT(i << " " << &h[i]);
new (&h[i]) hazptr_holder(nullptr); new (&h[i]) hazptr_holder(nullptr);
h[i].hazptr_ = hprec; h[i].hazptr_ = hprec;
DEBUG_PRINT( HAZPTR_DEBUG_PRINT(
i << " " << &h[i] << " " << h[i].domain_ << " " << h[i].hazptr_); i << " " << &h[i] << " " << h[i].domain_ << " " << h[i].hazptr_);
} }
tc.count_ = offset; tc.count_ = offset;
...@@ -480,7 +480,7 @@ FOLLY_ALWAYS_INLINE hazptr_array<M>::hazptr_array() { ...@@ -480,7 +480,7 @@ FOLLY_ALWAYS_INLINE hazptr_array<M>::hazptr_array() {
// slow path // slow path
for (size_t i = 0; i < M; ++i) { for (size_t i = 0; i < M; ++i) {
new (&h[i]) hazptr_holder; new (&h[i]) hazptr_holder;
DEBUG_PRINT( HAZPTR_DEBUG_PRINT(
i << " " << &h[i] << " " << h[i].domain_ << " " << h[i].hazptr_); i << " " << &h[i] << " " << h[i].domain_ << " " << h[i].hazptr_);
} }
} }
...@@ -488,12 +488,12 @@ FOLLY_ALWAYS_INLINE hazptr_array<M>::hazptr_array() { ...@@ -488,12 +488,12 @@ FOLLY_ALWAYS_INLINE hazptr_array<M>::hazptr_array() {
template <size_t M> template <size_t M>
FOLLY_ALWAYS_INLINE hazptr_array<M>::hazptr_array( FOLLY_ALWAYS_INLINE hazptr_array<M>::hazptr_array(
hazptr_array&& other) noexcept { hazptr_array&& other) noexcept {
DEBUG_PRINT(this << " " << M << " " << &other); HAZPTR_DEBUG_PRINT(this << " " << M << " " << &other);
auto h = reinterpret_cast<hazptr_holder*>(&raw_); auto h = reinterpret_cast<hazptr_holder*>(&raw_);
auto hother = reinterpret_cast<hazptr_holder*>(&other.raw_); auto hother = reinterpret_cast<hazptr_holder*>(&other.raw_);
for (size_t i = 0; i < M; ++i) { for (size_t i = 0; i < M; ++i) {
new (&h[i]) hazptr_holder(std::move(hother[i])); new (&h[i]) hazptr_holder(std::move(hother[i]));
DEBUG_PRINT(i << " " << &h[i] << " " << &hother[i]); HAZPTR_DEBUG_PRINT(i << " " << &h[i] << " " << &hother[i]);
} }
empty_ = other.empty_; empty_ = other.empty_;
other.empty_ = true; other.empty_ = true;
...@@ -501,11 +501,11 @@ FOLLY_ALWAYS_INLINE hazptr_array<M>::hazptr_array( ...@@ -501,11 +501,11 @@ FOLLY_ALWAYS_INLINE hazptr_array<M>::hazptr_array(
template <size_t M> template <size_t M>
FOLLY_ALWAYS_INLINE hazptr_array<M>::hazptr_array(std::nullptr_t) noexcept { FOLLY_ALWAYS_INLINE hazptr_array<M>::hazptr_array(std::nullptr_t) noexcept {
DEBUG_PRINT(this << " " << M); HAZPTR_DEBUG_PRINT(this << " " << M);
auto h = reinterpret_cast<hazptr_holder*>(&raw_); auto h = reinterpret_cast<hazptr_holder*>(&raw_);
for (size_t i = 0; i < M; ++i) { for (size_t i = 0; i < M; ++i) {
new (&h[i]) hazptr_holder(nullptr); new (&h[i]) hazptr_holder(nullptr);
DEBUG_PRINT(i << " " << &h[i]); HAZPTR_DEBUG_PRINT(i << " " << &h[i]);
} }
empty_ = true; empty_ = true;
} }
...@@ -524,9 +524,9 @@ FOLLY_ALWAYS_INLINE hazptr_array<M>::~hazptr_array() { ...@@ -524,9 +524,9 @@ FOLLY_ALWAYS_INLINE hazptr_array<M>::~hazptr_array() {
if ((M <= HAZPTR_TC_SIZE) && (count + M <= HAZPTR_TC_SIZE)) { if ((M <= HAZPTR_TC_SIZE) && (count + M <= HAZPTR_TC_SIZE)) {
for (size_t i = 0; i < M; ++i) { for (size_t i = 0; i < M; ++i) {
tc[count + i].hprec_ = h[i].hazptr_; tc[count + i].hprec_ = h[i].hazptr_;
DEBUG_PRINT(i << " " << &h[i]); HAZPTR_DEBUG_PRINT(i << " " << &h[i]);
new (&h[i]) hazptr_holder(nullptr); new (&h[i]) hazptr_holder(nullptr);
DEBUG_PRINT( HAZPTR_DEBUG_PRINT(
i << " " << &h[i] << " " << h[i].domain_ << " " << h[i].hazptr_); i << " " << &h[i] << " " << h[i].domain_ << " " << h[i].hazptr_);
} }
tc.count_ = count + M; tc.count_ = count + M;
...@@ -543,11 +543,11 @@ FOLLY_ALWAYS_INLINE hazptr_array<M>::~hazptr_array() { ...@@ -543,11 +543,11 @@ FOLLY_ALWAYS_INLINE hazptr_array<M>::~hazptr_array() {
template <size_t M> template <size_t M>
FOLLY_ALWAYS_INLINE hazptr_array<M>& hazptr_array<M>::operator=( FOLLY_ALWAYS_INLINE hazptr_array<M>& hazptr_array<M>::operator=(
hazptr_array&& other) noexcept { hazptr_array&& other) noexcept {
DEBUG_PRINT(this << " " << M << " " << &other); HAZPTR_DEBUG_PRINT(this << " " << M << " " << &other);
auto h = reinterpret_cast<hazptr_holder*>(&raw_); auto h = reinterpret_cast<hazptr_holder*>(&raw_);
for (size_t i = 0; i < M; ++i) { for (size_t i = 0; i < M; ++i) {
h[i] = std::move(other[i]); h[i] = std::move(other[i]);
DEBUG_PRINT(i << " " << &h[i] << " " << &other[i]); HAZPTR_DEBUG_PRINT(i << " " << &h[i] << " " << &other[i]);
} }
empty_ = other.empty_; empty_ = other.empty_;
other.empty_ = true; other.empty_ = true;
...@@ -583,10 +583,10 @@ FOLLY_ALWAYS_INLINE hazptr_local<M>::hazptr_local() { ...@@ -583,10 +583,10 @@ FOLLY_ALWAYS_INLINE hazptr_local<M>::hazptr_local() {
for (size_t i = 0; i < M; ++i) { for (size_t i = 0; i < M; ++i) {
auto hprec = tc[i].hprec_; auto hprec = tc[i].hprec_;
DCHECK(hprec != nullptr); DCHECK(hprec != nullptr);
DEBUG_PRINT(i << " " << &h[i]); HAZPTR_DEBUG_PRINT(i << " " << &h[i]);
new (&h[i]) hazptr_holder(nullptr); new (&h[i]) hazptr_holder(nullptr);
h[i].hazptr_ = hprec; h[i].hazptr_ = hprec;
DEBUG_PRINT( HAZPTR_DEBUG_PRINT(
i << " " << &h[i] << " " << h[i].domain_ << " " << h[i].hazptr_); i << " " << &h[i] << " " << h[i].domain_ << " " << h[i].hazptr_);
} }
return; return;
...@@ -597,7 +597,7 @@ FOLLY_ALWAYS_INLINE hazptr_local<M>::hazptr_local() { ...@@ -597,7 +597,7 @@ FOLLY_ALWAYS_INLINE hazptr_local<M>::hazptr_local() {
need_destruct_ = true; need_destruct_ = true;
for (size_t i = 0; i < M; ++i) { for (size_t i = 0; i < M; ++i) {
new (&h[i]) hazptr_holder; new (&h[i]) hazptr_holder;
DEBUG_PRINT( HAZPTR_DEBUG_PRINT(
i << " " << &h[i] << " " << h[i].domain_ << " " << h[i].hazptr_); i << " " << &h[i] << " " << h[i].domain_ << " " << h[i].hazptr_);
} }
} }
...@@ -637,7 +637,7 @@ FOLLY_ALWAYS_INLINE hazptr_holder& hazptr_local<M>::operator[]( ...@@ -637,7 +637,7 @@ FOLLY_ALWAYS_INLINE hazptr_holder& hazptr_local<M>::operator[](
/** Definition of default_hazptr_domain() */ /** Definition of default_hazptr_domain() */
FOLLY_ALWAYS_INLINE hazptr_domain& default_hazptr_domain() { FOLLY_ALWAYS_INLINE hazptr_domain& default_hazptr_domain() {
DEBUG_PRINT(&default_domain_); HAZPTR_DEBUG_PRINT(&default_domain_);
return default_domain_; return default_domain_;
} }
...@@ -649,18 +649,18 @@ FOLLY_ALWAYS_INLINE void hazptr_retire(T* obj, D reclaim) { ...@@ -649,18 +649,18 @@ FOLLY_ALWAYS_INLINE void hazptr_retire(T* obj, D reclaim) {
/** hazptr_rec */ /** hazptr_rec */
FOLLY_ALWAYS_INLINE void hazptr_rec::set(const void* p) noexcept { FOLLY_ALWAYS_INLINE void hazptr_rec::set(const void* p) noexcept {
DEBUG_PRINT(this << " " << p); HAZPTR_DEBUG_PRINT(this << " " << p);
hazptr_.store(p, std::memory_order_release); hazptr_.store(p, std::memory_order_release);
} }
inline const void* hazptr_rec::get() const noexcept { inline const void* hazptr_rec::get() const noexcept {
auto p = hazptr_.load(std::memory_order_acquire); auto p = hazptr_.load(std::memory_order_acquire);
DEBUG_PRINT(this << " " << p); HAZPTR_DEBUG_PRINT(this << " " << p);
return p; return p;
} }
FOLLY_ALWAYS_INLINE void hazptr_rec::clear() noexcept { FOLLY_ALWAYS_INLINE void hazptr_rec::clear() noexcept {
DEBUG_PRINT(this); HAZPTR_DEBUG_PRINT(this);
hazptr_.store(nullptr, std::memory_order_release); hazptr_.store(nullptr, std::memory_order_release);
} }
...@@ -673,21 +673,21 @@ inline bool hazptr_rec::tryAcquire() noexcept { ...@@ -673,21 +673,21 @@ inline bool hazptr_rec::tryAcquire() noexcept {
if (!active && if (!active &&
active_.compare_exchange_strong( active_.compare_exchange_strong(
active, true, std::memory_order_release, std::memory_order_relaxed)) { active, true, std::memory_order_release, std::memory_order_relaxed)) {
DEBUG_PRINT(this); HAZPTR_DEBUG_PRINT(this);
return true; return true;
} }
return false; return false;
} }
inline void hazptr_rec::release() noexcept { inline void hazptr_rec::release() noexcept {
DEBUG_PRINT(this); HAZPTR_DEBUG_PRINT(this);
active_.store(false, std::memory_order_release); active_.store(false, std::memory_order_release);
} }
/** hazptr_obj */ /** hazptr_obj */
inline const void* hazptr_obj::getObjPtr() const { inline const void* hazptr_obj::getObjPtr() const {
DEBUG_PRINT(this); HAZPTR_DEBUG_PRINT(this);
return this; return this;
} }
...@@ -710,7 +710,7 @@ void hazptr_domain::retire(T* obj, D reclaim) { ...@@ -710,7 +710,7 @@ void hazptr_domain::retire(T* obj, D reclaim) {
} }
inline hazptr_domain::~hazptr_domain() { inline hazptr_domain::~hazptr_domain() {
DEBUG_PRINT(this); HAZPTR_DEBUG_PRINT(this);
{ /* reclaim all remaining retired objects */ { /* reclaim all remaining retired objects */
hazptr_obj* next; hazptr_obj* next;
auto retired = retired_.exchange(nullptr); auto retired = retired_.exchange(nullptr);
...@@ -718,7 +718,7 @@ inline hazptr_domain::~hazptr_domain() { ...@@ -718,7 +718,7 @@ inline hazptr_domain::~hazptr_domain() {
for (auto p = retired; p; p = next) { for (auto p = retired; p; p = next) {
next = p->next_; next = p->next_;
DCHECK(p != next); DCHECK(p != next);
DEBUG_PRINT(this << " " << p << " " << p->reclaim_); HAZPTR_DEBUG_PRINT(this << " " << p << " " << p->reclaim_);
(*(p->reclaim_))(p); (*(p->reclaim_))(p);
} }
retired = retired_.exchange(nullptr); retired = retired_.exchange(nullptr);
...@@ -748,7 +748,7 @@ inline hazptr_rec* hazptr_domain::hazptrAcquire() { ...@@ -748,7 +748,7 @@ inline hazptr_rec* hazptr_domain::hazptrAcquire() {
} }
} }
p = static_cast<hazptr_rec*>(mr_->allocate(sizeof(hazptr_rec))); p = static_cast<hazptr_rec*>(mr_->allocate(sizeof(hazptr_rec)));
DEBUG_PRINT(this << " " << p << " " << sizeof(hazptr_rec)); HAZPTR_DEBUG_PRINT(this << " " << p << " " << sizeof(hazptr_rec));
if (p == nullptr) { if (p == nullptr) {
return nullptr; return nullptr;
} }
...@@ -759,12 +759,13 @@ inline hazptr_rec* hazptr_domain::hazptrAcquire() { ...@@ -759,12 +759,13 @@ inline hazptr_rec* hazptr_domain::hazptrAcquire() {
/* keep trying */; /* keep trying */;
} }
auto hcount = hcount_.fetch_add(1); auto hcount = hcount_.fetch_add(1);
DEBUG_PRINT(this << " " << p << " " << sizeof(hazptr_rec) << " " << hcount); HAZPTR_DEBUG_PRINT(
this << " " << p << " " << sizeof(hazptr_rec) << " " << hcount);
return p; return p;
} }
inline void hazptr_domain::hazptrRelease(hazptr_rec* p) noexcept { inline void hazptr_domain::hazptrRelease(hazptr_rec* p) noexcept {
DEBUG_PRINT(this << " " << p); HAZPTR_DEBUG_PRINT(this << " " << p);
p->release(); p->release();
} }
...@@ -795,7 +796,7 @@ inline void hazptr_domain::objRetire(hazptr_obj* p) { ...@@ -795,7 +796,7 @@ inline void hazptr_domain::objRetire(hazptr_obj* p) {
} }
inline void hazptr_domain::tryBulkReclaim() { inline void hazptr_domain::tryBulkReclaim() {
DEBUG_PRINT(this); HAZPTR_DEBUG_PRINT(this);
do { do {
auto hcount = hcount_.load(std::memory_order_acquire); auto hcount = hcount_.load(std::memory_order_acquire);
auto rcount = rcount_.load(std::memory_order_acquire); auto rcount = rcount_.load(std::memory_order_acquire);
...@@ -811,7 +812,7 @@ inline void hazptr_domain::tryBulkReclaim() { ...@@ -811,7 +812,7 @@ inline void hazptr_domain::tryBulkReclaim() {
} }
inline void hazptr_domain::bulkReclaim() { inline void hazptr_domain::bulkReclaim() {
DEBUG_PRINT(this); HAZPTR_DEBUG_PRINT(this);
/*** Full fence ***/ hazptr_mb::heavy(); /*** Full fence ***/ hazptr_mb::heavy();
auto p = retired_.exchange(nullptr, std::memory_order_acquire); auto p = retired_.exchange(nullptr, std::memory_order_acquire);
auto h = hazptrs_.load(std::memory_order_acquire); auto h = hazptrs_.load(std::memory_order_acquire);
...@@ -827,7 +828,7 @@ inline void hazptr_domain::bulkReclaim() { ...@@ -827,7 +828,7 @@ inline void hazptr_domain::bulkReclaim() {
next = p->next_; next = p->next_;
DCHECK(p != next); DCHECK(p != next);
if (hs.count(p->getObjPtr()) == 0) { if (hs.count(p->getObjPtr()) == 0) {
DEBUG_PRINT(this << " " << p << " " << p->reclaim_); HAZPTR_DEBUG_PRINT(this << " " << p << " " << p->reclaim_);
(*(p->reclaim_))(p); (*(p->reclaim_))(p);
} else { } else {
p->next_ = retired; p->next_ = retired;
...@@ -861,9 +862,9 @@ class hazptr_stats { ...@@ -861,9 +862,9 @@ class hazptr_stats {
extern hazptr_stats hazptr_stats_; extern hazptr_stats hazptr_stats_;
inline hazptr_stats::~hazptr_stats() { inline hazptr_stats::~hazptr_stats() {
DEBUG_PRINT(this << " light " << light_.load()); HAZPTR_DEBUG_PRINT(this << " light " << light_.load());
DEBUG_PRINT(this << " heavy " << heavy_.load()); HAZPTR_DEBUG_PRINT(this << " heavy " << heavy_.load());
DEBUG_PRINT(this << " seq_cst " << seq_cst_.load()); HAZPTR_DEBUG_PRINT(this << " seq_cst " << seq_cst_.load());
} }
FOLLY_ALWAYS_INLINE void hazptr_stats::light() { FOLLY_ALWAYS_INLINE void hazptr_stats::light() {
...@@ -887,7 +888,7 @@ inline void hazptr_stats::seq_cst() { ...@@ -887,7 +888,7 @@ inline void hazptr_stats::seq_cst() {
/** hazptr_mb */ /** hazptr_mb */
FOLLY_ALWAYS_INLINE void hazptr_mb::light() { FOLLY_ALWAYS_INLINE void hazptr_mb::light() {
DEBUG_PRINT(""); HAZPTR_DEBUG_PRINT("");
if (HAZPTR_AMB) { if (HAZPTR_AMB) {
folly::asymmetricLightBarrier(); folly::asymmetricLightBarrier();
INC_HAZPTR_STATS(light); INC_HAZPTR_STATS(light);
...@@ -898,7 +899,7 @@ FOLLY_ALWAYS_INLINE void hazptr_mb::light() { ...@@ -898,7 +899,7 @@ FOLLY_ALWAYS_INLINE void hazptr_mb::light() {
} }
inline void hazptr_mb::heavy() { inline void hazptr_mb::heavy() {
DEBUG_PRINT(""); HAZPTR_DEBUG_PRINT("");
if (HAZPTR_AMB) { if (HAZPTR_AMB) {
folly::asymmetricHeavyBarrier(AMBFlags::EXPEDITED); folly::asymmetricHeavyBarrier(AMBFlags::EXPEDITED);
INC_HAZPTR_STATS(heavy); INC_HAZPTR_STATS(heavy);
...@@ -920,19 +921,19 @@ inline void hazptr_mb::heavy() { ...@@ -920,19 +921,19 @@ inline void hazptr_mb::heavy() {
FOLLY_ALWAYS_INLINE void hazptr_tc_entry::fill(hazptr_rec* hprec) { FOLLY_ALWAYS_INLINE void hazptr_tc_entry::fill(hazptr_rec* hprec) {
hprec_ = hprec; hprec_ = hprec;
DEBUG_PRINT(this << " " << hprec); HAZPTR_DEBUG_PRINT(this << " " << hprec);
} }
FOLLY_ALWAYS_INLINE hazptr_rec* hazptr_tc_entry::get() { FOLLY_ALWAYS_INLINE hazptr_rec* hazptr_tc_entry::get() {
auto hprec = hprec_; auto hprec = hprec_;
DEBUG_PRINT(this << " " << hprec); HAZPTR_DEBUG_PRINT(this << " " << hprec);
return hprec; return hprec;
} }
inline void hazptr_tc_entry::evict() { inline void hazptr_tc_entry::evict() {
auto hprec = hprec_; auto hprec = hprec_;
hprec->release(); hprec->release();
DEBUG_PRINT(this << " " << hprec); HAZPTR_DEBUG_PRINT(this << " " << hprec);
} }
/** hazptr_tc */ /** hazptr_tc */
...@@ -945,17 +946,17 @@ FOLLY_ALWAYS_INLINE hazptr_tc_entry& hazptr_tc::operator[](size_t i) { ...@@ -945,17 +946,17 @@ FOLLY_ALWAYS_INLINE hazptr_tc_entry& hazptr_tc::operator[](size_t i) {
FOLLY_ALWAYS_INLINE hazptr_rec* hazptr_tc::get() { FOLLY_ALWAYS_INLINE hazptr_rec* hazptr_tc::get() {
if (LIKELY(count_ != 0)) { if (LIKELY(count_ != 0)) {
auto hprec = entry_[--count_].get(); auto hprec = entry_[--count_].get();
DEBUG_PRINT(this << " " << hprec); HAZPTR_DEBUG_PRINT(this << " " << hprec);
return hprec; return hprec;
} }
DEBUG_PRINT(this << " nullptr"); HAZPTR_DEBUG_PRINT(this << " nullptr");
return nullptr; return nullptr;
} }
FOLLY_ALWAYS_INLINE bool hazptr_tc::put(hazptr_rec* hprec) { FOLLY_ALWAYS_INLINE bool hazptr_tc::put(hazptr_rec* hprec) {
if (LIKELY(count_ < HAZPTR_TC_SIZE)) { if (LIKELY(count_ < HAZPTR_TC_SIZE)) {
entry_[count_++].fill(hprec); entry_[count_++].fill(hprec);
DEBUG_PRINT(this << " " << count_ - 1); HAZPTR_DEBUG_PRINT(this << " " << count_ - 1);
return true; return true;
} }
return false; return false;
...@@ -968,9 +969,9 @@ FOLLY_ALWAYS_INLINE size_t hazptr_tc::count() { ...@@ -968,9 +969,9 @@ FOLLY_ALWAYS_INLINE size_t hazptr_tc::count() {
/** hazptr_tc free functions */ /** hazptr_tc free functions */
FOLLY_ALWAYS_INLINE hazptr_tc* hazptr_tc_tls() { FOLLY_ALWAYS_INLINE hazptr_tc* hazptr_tc_tls() {
assert(hazptr_tc_enabled()); assert(hazptr_tc_enabled());
DEBUG_PRINT(tls_state_); HAZPTR_DEBUG_PRINT(tls_state_);
if (LIKELY(tls_state_ == TLS_ALIVE)) { if (LIKELY(tls_state_ == TLS_ALIVE)) {
DEBUG_PRINT(tls_state_); HAZPTR_DEBUG_PRINT(tls_state_);
return &tls_tc_data_; return &tls_tc_data_;
} else if (tls_state_ == TLS_UNINITIALIZED) { } else if (tls_state_ == TLS_UNINITIALIZED) {
tls_life_odr_use(); tls_life_odr_use();
...@@ -981,9 +982,9 @@ FOLLY_ALWAYS_INLINE hazptr_tc* hazptr_tc_tls() { ...@@ -981,9 +982,9 @@ FOLLY_ALWAYS_INLINE hazptr_tc* hazptr_tc_tls() {
inline void hazptr_tc_init() { inline void hazptr_tc_init() {
assert(hazptr_tc_enabled()); assert(hazptr_tc_enabled());
DEBUG_PRINT(""); HAZPTR_DEBUG_PRINT("");
auto& tc = tls_tc_data_; auto& tc = tls_tc_data_;
DEBUG_PRINT(&tc); HAZPTR_DEBUG_PRINT(&tc);
tc.count_ = 0; tc.count_ = 0;
if (kIsDebug) { if (kIsDebug) {
tc.local_ = false; tc.local_ = false;
...@@ -992,17 +993,17 @@ inline void hazptr_tc_init() { ...@@ -992,17 +993,17 @@ inline void hazptr_tc_init() {
inline void hazptr_tc_shutdown() { inline void hazptr_tc_shutdown() {
auto& tc = tls_tc_data_; auto& tc = tls_tc_data_;
DEBUG_PRINT(&tc); HAZPTR_DEBUG_PRINT(&tc);
for (size_t i = 0; i < tc.count_; ++i) { for (size_t i = 0; i < tc.count_; ++i) {
tc.entry_[i].evict(); tc.entry_[i].evict();
} }
} }
FOLLY_ALWAYS_INLINE hazptr_rec* hazptr_tc_try_get() { FOLLY_ALWAYS_INLINE hazptr_rec* hazptr_tc_try_get() {
DEBUG_PRINT(TLS_UNINITIALIZED << TLS_ALIVE << TLS_DESTROYED); HAZPTR_DEBUG_PRINT(TLS_UNINITIALIZED << TLS_ALIVE << TLS_DESTROYED);
DEBUG_PRINT(tls_state_); HAZPTR_DEBUG_PRINT(tls_state_);
if (LIKELY(tls_state_ == TLS_ALIVE)) { if (LIKELY(tls_state_ == TLS_ALIVE)) {
DEBUG_PRINT(tls_state_); HAZPTR_DEBUG_PRINT(tls_state_);
return tls_tc_data_.get(); return tls_tc_data_.get();
} else if (tls_state_ == TLS_UNINITIALIZED) { } else if (tls_state_ == TLS_UNINITIALIZED) {
tls_life_odr_use(); tls_life_odr_use();
...@@ -1012,9 +1013,9 @@ FOLLY_ALWAYS_INLINE hazptr_rec* hazptr_tc_try_get() { ...@@ -1012,9 +1013,9 @@ FOLLY_ALWAYS_INLINE hazptr_rec* hazptr_tc_try_get() {
} }
FOLLY_ALWAYS_INLINE bool hazptr_tc_try_put(hazptr_rec* hprec) { FOLLY_ALWAYS_INLINE bool hazptr_tc_try_put(hazptr_rec* hprec) {
DEBUG_PRINT(tls_state_); HAZPTR_DEBUG_PRINT(tls_state_);
if (LIKELY(tls_state_ == TLS_ALIVE)) { if (LIKELY(tls_state_ == TLS_ALIVE)) {
DEBUG_PRINT(tls_state_); HAZPTR_DEBUG_PRINT(tls_state_);
return tls_tc_data_.put(hprec); return tls_tc_data_.put(hprec);
} }
return false; return false;
...@@ -1054,7 +1055,7 @@ inline void hazptr_priv::pushAllToDomain() { ...@@ -1054,7 +1055,7 @@ inline void hazptr_priv::pushAllToDomain() {
inline void hazptr_priv_init() { inline void hazptr_priv_init() {
assert(hazptr_priv_enabled()); assert(hazptr_priv_enabled());
auto& priv = tls_priv_data_; auto& priv = tls_priv_data_;
DEBUG_PRINT(&priv); HAZPTR_DEBUG_PRINT(&priv);
priv.head_ = nullptr; priv.head_ = nullptr;
priv.tail_ = nullptr; priv.tail_ = nullptr;
priv.rcount_ = 0; priv.rcount_ = 0;
...@@ -1063,7 +1064,7 @@ inline void hazptr_priv_init() { ...@@ -1063,7 +1064,7 @@ inline void hazptr_priv_init() {
inline void hazptr_priv_shutdown() { inline void hazptr_priv_shutdown() {
auto& priv = tls_priv_data_; auto& priv = tls_priv_data_;
DEBUG_PRINT(&priv); HAZPTR_DEBUG_PRINT(&priv);
DCHECK(priv.active_); DCHECK(priv.active_);
priv.active_ = false; priv.active_ = false;
if (priv.tail_) { if (priv.tail_) {
...@@ -1072,13 +1073,13 @@ inline void hazptr_priv_shutdown() { ...@@ -1072,13 +1073,13 @@ inline void hazptr_priv_shutdown() {
} }
inline bool hazptr_priv_try_retire(hazptr_obj* obj) { inline bool hazptr_priv_try_retire(hazptr_obj* obj) {
DEBUG_PRINT(tls_state_); HAZPTR_DEBUG_PRINT(tls_state_);
if (tls_state_ == TLS_ALIVE) { if (tls_state_ == TLS_ALIVE) {
DEBUG_PRINT(tls_state_); HAZPTR_DEBUG_PRINT(tls_state_);
tls_priv_data_.push(obj); tls_priv_data_.push(obj);
return true; return true;
} else if (tls_state_ == TLS_UNINITIALIZED) { } else if (tls_state_ == TLS_UNINITIALIZED) {
DEBUG_PRINT(tls_state_); HAZPTR_DEBUG_PRINT(tls_state_);
tls_life_odr_use(); tls_life_odr_use();
tls_priv_data_.push(obj); tls_priv_data_.push(obj);
return true; return true;
...@@ -1089,15 +1090,15 @@ inline bool hazptr_priv_try_retire(hazptr_obj* obj) { ...@@ -1089,15 +1090,15 @@ inline bool hazptr_priv_try_retire(hazptr_obj* obj) {
/** hazptr_tls_life */ /** hazptr_tls_life */
inline void tls_life_odr_use() { inline void tls_life_odr_use() {
DEBUG_PRINT(tls_state_); HAZPTR_DEBUG_PRINT(tls_state_);
CHECK(tls_state_ == TLS_UNINITIALIZED); CHECK(tls_state_ == TLS_UNINITIALIZED);
auto volatile tlsOdrUse = &tls_life_; auto volatile tlsOdrUse = &tls_life_;
CHECK(tlsOdrUse != nullptr); CHECK(tlsOdrUse != nullptr);
DEBUG_PRINT(tlsOdrUse); HAZPTR_DEBUG_PRINT(tlsOdrUse);
} }
inline hazptr_tls_life::hazptr_tls_life() { inline hazptr_tls_life::hazptr_tls_life() {
DEBUG_PRINT(this); HAZPTR_DEBUG_PRINT(this);
CHECK(tls_state_ == TLS_UNINITIALIZED); CHECK(tls_state_ == TLS_UNINITIALIZED);
hazptr_tc_init(); hazptr_tc_init();
hazptr_priv_init(); hazptr_priv_init();
...@@ -1105,7 +1106,7 @@ inline hazptr_tls_life::hazptr_tls_life() { ...@@ -1105,7 +1106,7 @@ inline hazptr_tls_life::hazptr_tls_life() {
} }
inline hazptr_tls_life::~hazptr_tls_life() { inline hazptr_tls_life::~hazptr_tls_life() {
DEBUG_PRINT(this); HAZPTR_DEBUG_PRINT(this);
CHECK(tls_state_ == TLS_ALIVE); CHECK(tls_state_ == TLS_ALIVE);
hazptr_tc_shutdown(); hazptr_tc_shutdown();
hazptr_priv_shutdown(); hazptr_priv_shutdown();
......
...@@ -23,18 +23,18 @@ namespace { ...@@ -23,18 +23,18 @@ namespace {
memory_resource** default_mr_ptr() { memory_resource** default_mr_ptr() {
/* library-local */ static memory_resource* default_mr = /* library-local */ static memory_resource* default_mr =
new_delete_resource(); new_delete_resource();
DEBUG_PRINT(&default_mr << " " << default_mr); HAZPTR_DEBUG_PRINT(&default_mr << " " << default_mr);
return &default_mr; return &default_mr;
} }
} // namespace } // namespace
memory_resource* get_default_resource() { memory_resource* get_default_resource() {
DEBUG_PRINT(""); HAZPTR_DEBUG_PRINT("");
return *default_mr_ptr(); return *default_mr_ptr();
} }
void set_default_resource(memory_resource* mr) { void set_default_resource(memory_resource* mr) {
DEBUG_PRINT(""); HAZPTR_DEBUG_PRINT("");
*default_mr_ptr() = mr; *default_mr_ptr() = mr;
} }
...@@ -45,7 +45,7 @@ memory_resource* new_delete_resource() { ...@@ -45,7 +45,7 @@ memory_resource* new_delete_resource() {
override { override {
(void)alignment; (void)alignment;
void* p = static_cast<void*>(new char[bytes]); void* p = static_cast<void*>(new char[bytes]);
DEBUG_PRINT(this << " " << p << " " << bytes); HAZPTR_DEBUG_PRINT(this << " " << p << " " << bytes);
return p; return p;
} }
void deallocate( void deallocate(
...@@ -54,7 +54,7 @@ memory_resource* new_delete_resource() { ...@@ -54,7 +54,7 @@ memory_resource* new_delete_resource() {
const size_t alignment = max_align_v) override { const size_t alignment = max_align_v) override {
(void)alignment; (void)alignment;
(void)bytes; (void)bytes;
DEBUG_PRINT(p << " " << bytes); HAZPTR_DEBUG_PRINT(p << " " << bytes);
delete[] static_cast<char*>(p); delete[] static_cast<char*>(p);
} }
}; };
......
...@@ -40,29 +40,29 @@ using namespace folly::hazptr; ...@@ -40,29 +40,29 @@ using namespace folly::hazptr;
class HazptrTest : public testing::Test { class HazptrTest : public testing::Test {
public: public:
HazptrTest() : Test() { HazptrTest() : Test() {
DEBUG_PRINT("========== start of test scope"); HAZPTR_DEBUG_PRINT("========== start of test scope");
} }
~HazptrTest() override { ~HazptrTest() override {
DEBUG_PRINT("========== end of test scope"); HAZPTR_DEBUG_PRINT("========== end of test scope");
} }
}; };
TEST_F(HazptrTest, Test1) { TEST_F(HazptrTest, Test1) {
DEBUG_PRINT(""); HAZPTR_DEBUG_PRINT("");
Node1* node0 = (Node1*)malloc(sizeof(Node1)); Node1* node0 = (Node1*)malloc(sizeof(Node1));
node0 = new (node0) Node1; node0 = new (node0) Node1;
DEBUG_PRINT("=== malloc node0 " << node0 << " " << sizeof(*node0)); HAZPTR_DEBUG_PRINT("=== malloc node0 " << node0 << " " << sizeof(*node0));
Node1* node1 = (Node1*)malloc(sizeof(Node1)); Node1* node1 = (Node1*)malloc(sizeof(Node1));
node1 = new (node1) Node1; node1 = new (node1) Node1;
DEBUG_PRINT("=== malloc node1 " << node1 << " " << sizeof(*node1)); HAZPTR_DEBUG_PRINT("=== malloc node1 " << node1 << " " << sizeof(*node1));
Node1* node2 = (Node1*)malloc(sizeof(Node1)); Node1* node2 = (Node1*)malloc(sizeof(Node1));
node2 = new (node2) Node1; node2 = new (node2) Node1;
DEBUG_PRINT("=== malloc node2 " << node2 << " " << sizeof(*node2)); HAZPTR_DEBUG_PRINT("=== malloc node2 " << node2 << " " << sizeof(*node2));
Node1* node3 = (Node1*)malloc(sizeof(Node1)); Node1* node3 = (Node1*)malloc(sizeof(Node1));
node3 = new (node3) Node1; node3 = new (node3) Node1;
DEBUG_PRINT("=== malloc node3 " << node3 << " " << sizeof(*node3)); HAZPTR_DEBUG_PRINT("=== malloc node3 " << node3 << " " << sizeof(*node3));
DEBUG_PRINT(""); HAZPTR_DEBUG_PRINT("");
std::atomic<Node1*> shared0 = {node0}; std::atomic<Node1*> shared0 = {node0};
std::atomic<Node1*> shared1 = {node1}; std::atomic<Node1*> shared1 = {node1};
...@@ -70,24 +70,24 @@ TEST_F(HazptrTest, Test1) { ...@@ -70,24 +70,24 @@ TEST_F(HazptrTest, Test1) {
std::atomic<Node1*> shared3 = {node3}; std::atomic<Node1*> shared3 = {node3};
MyMemoryResource myMr; MyMemoryResource myMr;
DEBUG_PRINT("=== myMr " << &myMr); HAZPTR_DEBUG_PRINT("=== myMr " << &myMr);
hazptr_domain myDomain0; hazptr_domain myDomain0;
DEBUG_PRINT("=== myDomain0 " << &myDomain0); HAZPTR_DEBUG_PRINT("=== myDomain0 " << &myDomain0);
hazptr_domain myDomain1(&myMr); hazptr_domain myDomain1(&myMr);
DEBUG_PRINT("=== myDomain1 " << &myDomain1); HAZPTR_DEBUG_PRINT("=== myDomain1 " << &myDomain1);
DEBUG_PRINT(""); HAZPTR_DEBUG_PRINT("");
DEBUG_PRINT("=== hptr0"); HAZPTR_DEBUG_PRINT("=== hptr0");
hazptr_holder hptr0; hazptr_holder hptr0;
DEBUG_PRINT("=== hptr1"); HAZPTR_DEBUG_PRINT("=== hptr1");
hazptr_holder hptr1(myDomain0); hazptr_holder hptr1(myDomain0);
DEBUG_PRINT("=== hptr2"); HAZPTR_DEBUG_PRINT("=== hptr2");
hazptr_holder hptr2(myDomain1); hazptr_holder hptr2(myDomain1);
DEBUG_PRINT("=== hptr3"); HAZPTR_DEBUG_PRINT("=== hptr3");
hazptr_holder hptr3; hazptr_holder hptr3;
DEBUG_PRINT(""); HAZPTR_DEBUG_PRINT("");
Node1* n0 = shared0.load(); Node1* n0 = shared0.load();
Node1* n1 = shared1.load(); Node1* n1 = shared1.load();
...@@ -103,32 +103,32 @@ TEST_F(HazptrTest, Test1) { ...@@ -103,32 +103,32 @@ TEST_F(HazptrTest, Test1) {
swap(hptr1, hptr2); swap(hptr1, hptr2);
hptr3.reset(); hptr3.reset();
DEBUG_PRINT(""); HAZPTR_DEBUG_PRINT("");
DEBUG_PRINT("=== retire n0 " << n0); HAZPTR_DEBUG_PRINT("=== retire n0 " << n0);
n0->retire(); n0->retire();
DEBUG_PRINT("=== retire n1 " << n1); HAZPTR_DEBUG_PRINT("=== retire n1 " << n1);
n1->retire(default_hazptr_domain()); n1->retire(default_hazptr_domain());
DEBUG_PRINT("=== retire n2 " << n2); HAZPTR_DEBUG_PRINT("=== retire n2 " << n2);
n2->retire(myDomain0); n2->retire(myDomain0);
DEBUG_PRINT("=== retire n3 " << n3); HAZPTR_DEBUG_PRINT("=== retire n3 " << n3);
n3->retire(myDomain1); n3->retire(myDomain1);
} }
TEST_F(HazptrTest, Test2) { TEST_F(HazptrTest, Test2) {
Node2* node0 = new Node2; Node2* node0 = new Node2;
DEBUG_PRINT("=== new node0 " << node0 << " " << sizeof(*node0)); HAZPTR_DEBUG_PRINT("=== new node0 " << node0 << " " << sizeof(*node0));
Node2* node1 = (Node2*)malloc(sizeof(Node2)); Node2* node1 = (Node2*)malloc(sizeof(Node2));
node1 = new (node1) Node2; node1 = new (node1) Node2;
DEBUG_PRINT("=== malloc node1 " << node1 << " " << sizeof(*node1)); HAZPTR_DEBUG_PRINT("=== malloc node1 " << node1 << " " << sizeof(*node1));
Node2* node2 = (Node2*)malloc(sizeof(Node2)); Node2* node2 = (Node2*)malloc(sizeof(Node2));
node2 = new (node2) Node2; node2 = new (node2) Node2;
DEBUG_PRINT("=== malloc node2 " << node2 << " " << sizeof(*node2)); HAZPTR_DEBUG_PRINT("=== malloc node2 " << node2 << " " << sizeof(*node2));
Node2* node3 = (Node2*)malloc(sizeof(Node2)); Node2* node3 = (Node2*)malloc(sizeof(Node2));
node3 = new (node3) Node2; node3 = new (node3) Node2;
DEBUG_PRINT("=== malloc node3 " << node3 << " " << sizeof(*node3)); HAZPTR_DEBUG_PRINT("=== malloc node3 " << node3 << " " << sizeof(*node3));
DEBUG_PRINT(""); HAZPTR_DEBUG_PRINT("");
std::atomic<Node2*> shared0 = {node0}; std::atomic<Node2*> shared0 = {node0};
std::atomic<Node2*> shared1 = {node1}; std::atomic<Node2*> shared1 = {node1};
...@@ -136,24 +136,24 @@ TEST_F(HazptrTest, Test2) { ...@@ -136,24 +136,24 @@ TEST_F(HazptrTest, Test2) {
std::atomic<Node2*> shared3 = {node3}; std::atomic<Node2*> shared3 = {node3};
MineMemoryResource mineMr; MineMemoryResource mineMr;
DEBUG_PRINT("=== mineMr " << &mineMr); HAZPTR_DEBUG_PRINT("=== mineMr " << &mineMr);
hazptr_domain mineDomain0; hazptr_domain mineDomain0;
DEBUG_PRINT("=== mineDomain0 " << &mineDomain0); HAZPTR_DEBUG_PRINT("=== mineDomain0 " << &mineDomain0);
hazptr_domain mineDomain1(&mineMr); hazptr_domain mineDomain1(&mineMr);
DEBUG_PRINT("=== mineDomain1 " << &mineDomain1); HAZPTR_DEBUG_PRINT("=== mineDomain1 " << &mineDomain1);
DEBUG_PRINT(""); HAZPTR_DEBUG_PRINT("");
DEBUG_PRINT("=== hptr0"); HAZPTR_DEBUG_PRINT("=== hptr0");
hazptr_holder hptr0; hazptr_holder hptr0;
DEBUG_PRINT("=== hptr1"); HAZPTR_DEBUG_PRINT("=== hptr1");
hazptr_holder hptr1(mineDomain0); hazptr_holder hptr1(mineDomain0);
DEBUG_PRINT("=== hptr2"); HAZPTR_DEBUG_PRINT("=== hptr2");
hazptr_holder hptr2(mineDomain1); hazptr_holder hptr2(mineDomain1);
DEBUG_PRINT("=== hptr3"); HAZPTR_DEBUG_PRINT("=== hptr3");
hazptr_holder hptr3; hazptr_holder hptr3;
DEBUG_PRINT(""); HAZPTR_DEBUG_PRINT("");
Node2* n0 = shared0.load(); Node2* n0 = shared0.load();
Node2* n1 = shared1.load(); Node2* n1 = shared1.load();
...@@ -168,15 +168,15 @@ TEST_F(HazptrTest, Test2) { ...@@ -168,15 +168,15 @@ TEST_F(HazptrTest, Test2) {
swap(hptr1, hptr2); swap(hptr1, hptr2);
hptr3.reset(); hptr3.reset();
DEBUG_PRINT(""); HAZPTR_DEBUG_PRINT("");
DEBUG_PRINT("=== retire n0 " << n0); HAZPTR_DEBUG_PRINT("=== retire n0 " << n0);
n0->retire(default_hazptr_domain(), &mineReclaimFnDelete); n0->retire(default_hazptr_domain(), &mineReclaimFnDelete);
DEBUG_PRINT("=== retire n1 " << n1); HAZPTR_DEBUG_PRINT("=== retire n1 " << n1);
n1->retire(default_hazptr_domain(), &mineReclaimFnFree); n1->retire(default_hazptr_domain(), &mineReclaimFnFree);
DEBUG_PRINT("=== retire n2 " << n2); HAZPTR_DEBUG_PRINT("=== retire n2 " << n2);
n2->retire(mineDomain0, &mineReclaimFnFree); n2->retire(mineDomain0, &mineReclaimFnFree);
DEBUG_PRINT("=== retire n3 " << n3); HAZPTR_DEBUG_PRINT("=== retire n3 " << n3);
n3->retire(mineDomain1, &mineReclaimFnFree); n3->retire(mineDomain1, &mineReclaimFnFree);
} }
...@@ -184,7 +184,7 @@ TEST_F(HazptrTest, LIFO) { ...@@ -184,7 +184,7 @@ TEST_F(HazptrTest, LIFO) {
using T = uint32_t; using T = uint32_t;
CHECK_GT(FLAGS_num_threads, 0); CHECK_GT(FLAGS_num_threads, 0);
for (int i = 0; i < FLAGS_num_reps; ++i) { for (int i = 0; i < FLAGS_num_reps; ++i) {
DEBUG_PRINT("========== start of rep scope"); HAZPTR_DEBUG_PRINT("========== start of rep scope");
LockFreeLIFO<T> s; LockFreeLIFO<T> s;
std::vector<std::thread> threads(FLAGS_num_threads); std::vector<std::thread> threads(FLAGS_num_threads);
for (int tid = 0; tid < FLAGS_num_threads; ++tid) { for (int tid = 0; tid < FLAGS_num_threads; ++tid) {
...@@ -201,7 +201,7 @@ TEST_F(HazptrTest, LIFO) { ...@@ -201,7 +201,7 @@ TEST_F(HazptrTest, LIFO) {
for (auto& t : threads) { for (auto& t : threads) {
t.join(); t.join();
} }
DEBUG_PRINT("========== end of rep scope"); HAZPTR_DEBUG_PRINT("========== end of rep scope");
} }
} }
...@@ -210,7 +210,7 @@ TEST_F(HazptrTest, SWMRLIST) { ...@@ -210,7 +210,7 @@ TEST_F(HazptrTest, SWMRLIST) {
CHECK_GT(FLAGS_num_threads, 0); CHECK_GT(FLAGS_num_threads, 0);
for (int i = 0; i < FLAGS_num_reps; ++i) { for (int i = 0; i < FLAGS_num_reps; ++i) {
DEBUG_PRINT("========== start of rep scope"); HAZPTR_DEBUG_PRINT("========== start of rep scope");
SWMRListSet<T> s; SWMRListSet<T> s;
std::vector<std::thread> threads(FLAGS_num_threads); std::vector<std::thread> threads(FLAGS_num_threads);
for (int tid = 0; tid < FLAGS_num_threads; ++tid) { for (int tid = 0; tid < FLAGS_num_threads; ++tid) {
...@@ -229,7 +229,7 @@ TEST_F(HazptrTest, SWMRLIST) { ...@@ -229,7 +229,7 @@ TEST_F(HazptrTest, SWMRLIST) {
for (auto& t : threads) { for (auto& t : threads) {
t.join(); t.join();
} }
DEBUG_PRINT("========== end of rep scope"); HAZPTR_DEBUG_PRINT("========== end of rep scope");
} }
} }
...@@ -238,7 +238,7 @@ TEST_F(HazptrTest, MWMRSet) { ...@@ -238,7 +238,7 @@ TEST_F(HazptrTest, MWMRSet) {
CHECK_GT(FLAGS_num_threads, 0); CHECK_GT(FLAGS_num_threads, 0);
for (int i = 0; i < FLAGS_num_reps; ++i) { for (int i = 0; i < FLAGS_num_reps; ++i) {
DEBUG_PRINT("========== start of rep scope"); HAZPTR_DEBUG_PRINT("========== start of rep scope");
MWMRListSet<T> s; MWMRListSet<T> s;
std::vector<std::thread> threads(FLAGS_num_threads); std::vector<std::thread> threads(FLAGS_num_threads);
for (int tid = 0; tid < FLAGS_num_threads; ++tid) { for (int tid = 0; tid < FLAGS_num_threads; ++tid) {
...@@ -259,7 +259,7 @@ TEST_F(HazptrTest, MWMRSet) { ...@@ -259,7 +259,7 @@ TEST_F(HazptrTest, MWMRSet) {
for (auto& t : threads) { for (auto& t : threads) {
t.join(); t.join();
} }
DEBUG_PRINT("========== end of rep scope"); HAZPTR_DEBUG_PRINT("========== end of rep scope");
} }
} }
...@@ -286,7 +286,7 @@ TEST_F(HazptrTest, WIDECAS) { ...@@ -286,7 +286,7 @@ TEST_F(HazptrTest, WIDECAS) {
TEST_F(HazptrTest, VirtualTest) { TEST_F(HazptrTest, VirtualTest) {
struct Thing : public hazptr_obj_base<Thing> { struct Thing : public hazptr_obj_base<Thing> {
virtual ~Thing() { virtual ~Thing() {
DEBUG_PRINT("this: " << this << " &a: " << &a << " a: " << a); HAZPTR_DEBUG_PRINT("this: " << this << " &a: " << &a << " a: " << a);
} }
int a; int a;
}; };
...@@ -308,7 +308,8 @@ void destructionTest(hazptr_domain& domain) { ...@@ -308,7 +308,8 @@ void destructionTest(hazptr_domain& domain) {
int val; int val;
Thing(int v, Thing* n, hazptr_domain* d) : next(n), domain(d), val(v) {} Thing(int v, Thing* n, hazptr_domain* d) : next(n), domain(d), val(v) {}
~Thing() { ~Thing() {
DEBUG_PRINT("this: " << this << " val: " << val << " next: " << next); HAZPTR_DEBUG_PRINT(
"this: " << this << " val: " << val << " next: " << next);
if (next) { if (next) {
next->retire(*domain); next->retire(*domain);
} }
...@@ -415,11 +416,11 @@ struct Foo : hazptr_obj_base_refcounted<Foo> { ...@@ -415,11 +416,11 @@ struct Foo : hazptr_obj_base_refcounted<Foo> {
bool marked_; bool marked_;
Foo* next_; Foo* next_;
Foo(int v, Foo* n) : val_(v), marked_(false), next_(n) { Foo(int v, Foo* n) : val_(v), marked_(false), next_(n) {
DEBUG_PRINT(""); HAZPTR_DEBUG_PRINT("");
++constructed; ++constructed;
} }
~Foo() { ~Foo() {
DEBUG_PRINT(""); HAZPTR_DEBUG_PRINT("");
++destroyed; ++destroyed;
if (marked_) { if (marked_) {
return; return;
...@@ -530,11 +531,11 @@ TEST_F(HazptrTest, mt_refcount) { ...@@ -530,11 +531,11 @@ TEST_F(HazptrTest, mt_refcount) {
for (auto q = p; q; q = q->next_) { for (auto q = p; q; q = q->next_) {
q->retire(); q->retire();
} }
DEBUG_PRINT("Foo should not be destroyed"); HAZPTR_DEBUG_PRINT("Foo should not be destroyed");
CHECK_EQ(constructed.load(), num); CHECK_EQ(constructed.load(), num);
CHECK_EQ(destroyed.load(), 0); CHECK_EQ(destroyed.load(), 0);
DEBUG_PRINT("Foo may be destroyed after releasing the last reference"); HAZPTR_DEBUG_PRINT("Foo may be destroyed after releasing the last reference");
if (p->release_ref()) { if (p->release_ref()) {
delete p; delete p;
} }
......
...@@ -25,12 +25,12 @@ class MyMemoryResource : public memory_resource { ...@@ -25,12 +25,12 @@ class MyMemoryResource : public memory_resource {
public: public:
void* allocate(const size_t sz, const size_t /* align */) override { void* allocate(const size_t sz, const size_t /* align */) override {
void* p = malloc(sz); void* p = malloc(sz);
DEBUG_PRINT(p << " " << sz); HAZPTR_DEBUG_PRINT(p << " " << sz);
return p; return p;
} }
void deallocate(void* p, const size_t sz, const size_t /* align */) override { void deallocate(void* p, const size_t sz, const size_t /* align */) override {
DEBUG_PRINT(p << " " << sz); HAZPTR_DEBUG_PRINT(p << " " << sz);
free(p); free(p);
} }
}; };
...@@ -38,7 +38,7 @@ class MyMemoryResource : public memory_resource { ...@@ -38,7 +38,7 @@ class MyMemoryResource : public memory_resource {
template <typename Node1> template <typename Node1>
struct MyReclaimerFree { struct MyReclaimerFree {
inline void operator()(Node1* p) { inline void operator()(Node1* p) {
DEBUG_PRINT(p << " " << sizeof(Node1)); HAZPTR_DEBUG_PRINT(p << " " << sizeof(Node1));
free(p); free(p);
} }
}; };
......
...@@ -25,12 +25,12 @@ class MineMemoryResource : public memory_resource { ...@@ -25,12 +25,12 @@ class MineMemoryResource : public memory_resource {
public: public:
void* allocate(const size_t sz, const size_t /* align */) override { void* allocate(const size_t sz, const size_t /* align */) override {
void* p = malloc(sz); void* p = malloc(sz);
DEBUG_PRINT(p << " " << sz); HAZPTR_DEBUG_PRINT(p << " " << sz);
return p; return p;
} }
void deallocate(void* p, const size_t sz, const size_t /* align */) override { void deallocate(void* p, const size_t sz, const size_t /* align */) override {
DEBUG_PRINT(p << " " << sz); HAZPTR_DEBUG_PRINT(p << " " << sz);
free(p); free(p);
} }
}; };
...@@ -40,12 +40,12 @@ class Node2 : public hazptr_obj_base<Node2, void (*)(Node2*)> { ...@@ -40,12 +40,12 @@ class Node2 : public hazptr_obj_base<Node2, void (*)(Node2*)> {
}; };
inline void mineReclaimFnFree(Node2* p) { inline void mineReclaimFnFree(Node2* p) {
DEBUG_PRINT(p << " " << sizeof(Node2)); HAZPTR_DEBUG_PRINT(p << " " << sizeof(Node2));
free(p); free(p);
} }
inline void mineReclaimFnDelete(Node2* p) { inline void mineReclaimFnDelete(Node2* p) {
DEBUG_PRINT(p << " " << sizeof(Node2)); HAZPTR_DEBUG_PRINT(p << " " << sizeof(Node2));
delete p; delete p;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment