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 @@
#define HAZPTR_DEBUG false
#endif
#define DEBUG_PRINT(...) \
#define HAZPTR_DEBUG_PRINT(...) \
do { \
if (HAZPTR_DEBUG) { \
VLOG(2) << __func__ << " --- " << __VA_ARGS__; \
......
......@@ -27,11 +27,11 @@ class LockFreeLIFO {
friend LockFreeLIFO;
public:
~Node() {
DEBUG_PRINT(this);
HAZPTR_DEBUG_PRINT(this);
}
private:
Node(T v, Node* n) : value_(v), next_(n) {
DEBUG_PRINT(this);
HAZPTR_DEBUG_PRINT(this);
}
T value_;
Node* next_;
......@@ -39,15 +39,15 @@ class LockFreeLIFO {
public:
LockFreeLIFO() {
DEBUG_PRINT(this);
HAZPTR_DEBUG_PRINT(this);
}
~LockFreeLIFO() {
DEBUG_PRINT(this);
HAZPTR_DEBUG_PRINT(this);
}
void push(T val) {
DEBUG_PRINT(this);
HAZPTR_DEBUG_PRINT(this);
auto pnode = new Node(val, head_.load());
while (!head_.compare_exchange_weak(pnode->next_, pnode)) {
;
......@@ -55,7 +55,7 @@ class LockFreeLIFO {
}
bool pop(T& val) {
DEBUG_PRINT(this);
HAZPTR_DEBUG_PRINT(this);
hazptr_holder hptr;
Node* pnode = head_.load();
do {
......
......@@ -65,11 +65,11 @@ class MWMRListSet {
public:
explicit Node(T e) : elem_(e) {
DEBUG_PRINT(this << " " << e);
HAZPTR_DEBUG_PRINT(this << " " << e);
}
~Node() {
DEBUG_PRINT(this);
HAZPTR_DEBUG_PRINT(this);
auto next = getPtr(next_.load(std::memory_order_relaxed));
if (next) {
next->release();
......
......@@ -32,7 +32,7 @@ class SWMRListSet {
template <typename Node>
struct Reclaimer {
void operator()(Node* p) {
DEBUG_PRINT(p << " " << sizeof(Node));
HAZPTR_DEBUG_PRINT(p << " " << sizeof(Node));
delete p;
}
};
......@@ -43,12 +43,12 @@ class SWMRListSet {
std::atomic<Node*> next_;
Node(T e, Node* n) : elem_(e), next_(n) {
DEBUG_PRINT(this << " " << e << " " << n);
HAZPTR_DEBUG_PRINT(this << " " << e << " " << n);
}
public:
~Node() {
DEBUG_PRINT(this);
HAZPTR_DEBUG_PRINT(this);
}
};
......
......@@ -30,10 +30,17 @@ class WideCAS {
class Node : public hazptr_obj_base<Node> {
friend WideCAS;
T val_;
Node() : val_(T()) { DEBUG_PRINT(this << " " << val_); }
explicit Node(T v) : val_(v) { DEBUG_PRINT(this << " " << v); }
Node() : val_(T()) {
HAZPTR_DEBUG_PRINT(this << " " << val_);
}
explicit Node(T v) : val_(v) {
HAZPTR_DEBUG_PRINT(this << " " << v);
}
public:
~Node() { DEBUG_PRINT(this); }
~Node() {
HAZPTR_DEBUG_PRINT(this);
}
};
std::atomic<Node*> p_ = {new Node()};
......@@ -41,12 +48,12 @@ class WideCAS {
public:
WideCAS() = default;
~WideCAS() {
DEBUG_PRINT(this << " " << p_.load());
HAZPTR_DEBUG_PRINT(this << " " << p_.load());
delete p_.load();
}
bool cas(T& u, T& v) {
DEBUG_PRINT(this << " " << u << " " << v);
HAZPTR_DEBUG_PRINT(this << " " << u << " " << v);
Node* n = new Node(v);
hazptr_holder hptr;
Node* p;
......@@ -59,7 +66,7 @@ class WideCAS {
} while (true);
hptr.reset();
p->retire();
DEBUG_PRINT(this << " " << p << " " << u << " " << n << " " << v);
HAZPTR_DEBUG_PRINT(this << " " << p << " " << u << " " << n << " " << v);
return true;
}
};
......
This diff is collapsed.
......@@ -23,18 +23,18 @@ namespace {
memory_resource** default_mr_ptr() {
/* library-local */ static memory_resource* default_mr =
new_delete_resource();
DEBUG_PRINT(&default_mr << " " << default_mr);
HAZPTR_DEBUG_PRINT(&default_mr << " " << default_mr);
return &default_mr;
}
} // namespace
memory_resource* get_default_resource() {
DEBUG_PRINT("");
HAZPTR_DEBUG_PRINT("");
return *default_mr_ptr();
}
void set_default_resource(memory_resource* mr) {
DEBUG_PRINT("");
HAZPTR_DEBUG_PRINT("");
*default_mr_ptr() = mr;
}
......@@ -45,7 +45,7 @@ memory_resource* new_delete_resource() {
override {
(void)alignment;
void* p = static_cast<void*>(new char[bytes]);
DEBUG_PRINT(this << " " << p << " " << bytes);
HAZPTR_DEBUG_PRINT(this << " " << p << " " << bytes);
return p;
}
void deallocate(
......@@ -54,7 +54,7 @@ memory_resource* new_delete_resource() {
const size_t alignment = max_align_v) override {
(void)alignment;
(void)bytes;
DEBUG_PRINT(p << " " << bytes);
HAZPTR_DEBUG_PRINT(p << " " << bytes);
delete[] static_cast<char*>(p);
}
};
......
......@@ -40,29 +40,29 @@ using namespace folly::hazptr;
class HazptrTest : public testing::Test {
public:
HazptrTest() : Test() {
DEBUG_PRINT("========== start of test scope");
HAZPTR_DEBUG_PRINT("========== start of test scope");
}
~HazptrTest() override {
DEBUG_PRINT("========== end of test scope");
HAZPTR_DEBUG_PRINT("========== end of test scope");
}
};
TEST_F(HazptrTest, Test1) {
DEBUG_PRINT("");
HAZPTR_DEBUG_PRINT("");
Node1* node0 = (Node1*)malloc(sizeof(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 = new (node1) Node1;
DEBUG_PRINT("=== malloc node1 " << node1 << " " << sizeof(*node1));
HAZPTR_DEBUG_PRINT("=== malloc node1 " << node1 << " " << sizeof(*node1));
Node1* node2 = (Node1*)malloc(sizeof(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));
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*> shared1 = {node1};
......@@ -70,24 +70,24 @@ TEST_F(HazptrTest, Test1) {
std::atomic<Node1*> shared3 = {node3};
MyMemoryResource myMr;
DEBUG_PRINT("=== myMr " << &myMr);
HAZPTR_DEBUG_PRINT("=== myMr " << &myMr);
hazptr_domain myDomain0;
DEBUG_PRINT("=== myDomain0 " << &myDomain0);
HAZPTR_DEBUG_PRINT("=== myDomain0 " << &myDomain0);
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;
DEBUG_PRINT("=== hptr1");
HAZPTR_DEBUG_PRINT("=== hptr1");
hazptr_holder hptr1(myDomain0);
DEBUG_PRINT("=== hptr2");
HAZPTR_DEBUG_PRINT("=== hptr2");
hazptr_holder hptr2(myDomain1);
DEBUG_PRINT("=== hptr3");
HAZPTR_DEBUG_PRINT("=== hptr3");
hazptr_holder hptr3;
DEBUG_PRINT("");
HAZPTR_DEBUG_PRINT("");
Node1* n0 = shared0.load();
Node1* n1 = shared1.load();
......@@ -103,32 +103,32 @@ TEST_F(HazptrTest, Test1) {
swap(hptr1, hptr2);
hptr3.reset();
DEBUG_PRINT("");
HAZPTR_DEBUG_PRINT("");
DEBUG_PRINT("=== retire n0 " << n0);
HAZPTR_DEBUG_PRINT("=== retire n0 " << n0);
n0->retire();
DEBUG_PRINT("=== retire n1 " << n1);
HAZPTR_DEBUG_PRINT("=== retire n1 " << n1);
n1->retire(default_hazptr_domain());
DEBUG_PRINT("=== retire n2 " << n2);
HAZPTR_DEBUG_PRINT("=== retire n2 " << n2);
n2->retire(myDomain0);
DEBUG_PRINT("=== retire n3 " << n3);
HAZPTR_DEBUG_PRINT("=== retire n3 " << n3);
n3->retire(myDomain1);
}
TEST_F(HazptrTest, Test2) {
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));
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 = new (node2) Node2;
DEBUG_PRINT("=== malloc node2 " << node2 << " " << sizeof(*node2));
HAZPTR_DEBUG_PRINT("=== malloc node2 " << node2 << " " << sizeof(*node2));
Node2* node3 = (Node2*)malloc(sizeof(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*> shared1 = {node1};
......@@ -136,24 +136,24 @@ TEST_F(HazptrTest, Test2) {
std::atomic<Node2*> shared3 = {node3};
MineMemoryResource mineMr;
DEBUG_PRINT("=== mineMr " << &mineMr);
HAZPTR_DEBUG_PRINT("=== mineMr " << &mineMr);
hazptr_domain mineDomain0;
DEBUG_PRINT("=== mineDomain0 " << &mineDomain0);
HAZPTR_DEBUG_PRINT("=== mineDomain0 " << &mineDomain0);
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;
DEBUG_PRINT("=== hptr1");
HAZPTR_DEBUG_PRINT("=== hptr1");
hazptr_holder hptr1(mineDomain0);
DEBUG_PRINT("=== hptr2");
HAZPTR_DEBUG_PRINT("=== hptr2");
hazptr_holder hptr2(mineDomain1);
DEBUG_PRINT("=== hptr3");
HAZPTR_DEBUG_PRINT("=== hptr3");
hazptr_holder hptr3;
DEBUG_PRINT("");
HAZPTR_DEBUG_PRINT("");
Node2* n0 = shared0.load();
Node2* n1 = shared1.load();
......@@ -168,15 +168,15 @@ TEST_F(HazptrTest, Test2) {
swap(hptr1, hptr2);
hptr3.reset();
DEBUG_PRINT("");
HAZPTR_DEBUG_PRINT("");
DEBUG_PRINT("=== retire n0 " << n0);
HAZPTR_DEBUG_PRINT("=== retire n0 " << n0);
n0->retire(default_hazptr_domain(), &mineReclaimFnDelete);
DEBUG_PRINT("=== retire n1 " << n1);
HAZPTR_DEBUG_PRINT("=== retire n1 " << n1);
n1->retire(default_hazptr_domain(), &mineReclaimFnFree);
DEBUG_PRINT("=== retire n2 " << n2);
HAZPTR_DEBUG_PRINT("=== retire n2 " << n2);
n2->retire(mineDomain0, &mineReclaimFnFree);
DEBUG_PRINT("=== retire n3 " << n3);
HAZPTR_DEBUG_PRINT("=== retire n3 " << n3);
n3->retire(mineDomain1, &mineReclaimFnFree);
}
......@@ -184,7 +184,7 @@ TEST_F(HazptrTest, LIFO) {
using T = uint32_t;
CHECK_GT(FLAGS_num_threads, 0);
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;
std::vector<std::thread> threads(FLAGS_num_threads);
for (int tid = 0; tid < FLAGS_num_threads; ++tid) {
......@@ -201,7 +201,7 @@ TEST_F(HazptrTest, LIFO) {
for (auto& t : threads) {
t.join();
}
DEBUG_PRINT("========== end of rep scope");
HAZPTR_DEBUG_PRINT("========== end of rep scope");
}
}
......@@ -210,7 +210,7 @@ TEST_F(HazptrTest, SWMRLIST) {
CHECK_GT(FLAGS_num_threads, 0);
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;
std::vector<std::thread> threads(FLAGS_num_threads);
for (int tid = 0; tid < FLAGS_num_threads; ++tid) {
......@@ -229,7 +229,7 @@ TEST_F(HazptrTest, SWMRLIST) {
for (auto& t : threads) {
t.join();
}
DEBUG_PRINT("========== end of rep scope");
HAZPTR_DEBUG_PRINT("========== end of rep scope");
}
}
......@@ -238,7 +238,7 @@ TEST_F(HazptrTest, MWMRSet) {
CHECK_GT(FLAGS_num_threads, 0);
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;
std::vector<std::thread> threads(FLAGS_num_threads);
for (int tid = 0; tid < FLAGS_num_threads; ++tid) {
......@@ -259,7 +259,7 @@ TEST_F(HazptrTest, MWMRSet) {
for (auto& t : threads) {
t.join();
}
DEBUG_PRINT("========== end of rep scope");
HAZPTR_DEBUG_PRINT("========== end of rep scope");
}
}
......@@ -286,7 +286,7 @@ TEST_F(HazptrTest, WIDECAS) {
TEST_F(HazptrTest, VirtualTest) {
struct Thing : public hazptr_obj_base<Thing> {
virtual ~Thing() {
DEBUG_PRINT("this: " << this << " &a: " << &a << " a: " << a);
HAZPTR_DEBUG_PRINT("this: " << this << " &a: " << &a << " a: " << a);
}
int a;
};
......@@ -308,7 +308,8 @@ void destructionTest(hazptr_domain& domain) {
int val;
Thing(int v, Thing* n, hazptr_domain* d) : next(n), domain(d), val(v) {}
~Thing() {
DEBUG_PRINT("this: " << this << " val: " << val << " next: " << next);
HAZPTR_DEBUG_PRINT(
"this: " << this << " val: " << val << " next: " << next);
if (next) {
next->retire(*domain);
}
......@@ -415,11 +416,11 @@ struct Foo : hazptr_obj_base_refcounted<Foo> {
bool marked_;
Foo* next_;
Foo(int v, Foo* n) : val_(v), marked_(false), next_(n) {
DEBUG_PRINT("");
HAZPTR_DEBUG_PRINT("");
++constructed;
}
~Foo() {
DEBUG_PRINT("");
HAZPTR_DEBUG_PRINT("");
++destroyed;
if (marked_) {
return;
......@@ -530,11 +531,11 @@ TEST_F(HazptrTest, mt_refcount) {
for (auto q = p; q; q = q->next_) {
q->retire();
}
DEBUG_PRINT("Foo should not be destroyed");
HAZPTR_DEBUG_PRINT("Foo should not be destroyed");
CHECK_EQ(constructed.load(), num);
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()) {
delete p;
}
......
......@@ -25,12 +25,12 @@ class MyMemoryResource : public memory_resource {
public:
void* allocate(const size_t sz, const size_t /* align */) override {
void* p = malloc(sz);
DEBUG_PRINT(p << " " << sz);
HAZPTR_DEBUG_PRINT(p << " " << sz);
return p;
}
void deallocate(void* p, const size_t sz, const size_t /* align */) override {
DEBUG_PRINT(p << " " << sz);
HAZPTR_DEBUG_PRINT(p << " " << sz);
free(p);
}
};
......@@ -38,7 +38,7 @@ class MyMemoryResource : public memory_resource {
template <typename Node1>
struct MyReclaimerFree {
inline void operator()(Node1* p) {
DEBUG_PRINT(p << " " << sizeof(Node1));
HAZPTR_DEBUG_PRINT(p << " " << sizeof(Node1));
free(p);
}
};
......
......@@ -25,12 +25,12 @@ class MineMemoryResource : public memory_resource {
public:
void* allocate(const size_t sz, const size_t /* align */) override {
void* p = malloc(sz);
DEBUG_PRINT(p << " " << sz);
HAZPTR_DEBUG_PRINT(p << " " << sz);
return p;
}
void deallocate(void* p, const size_t sz, const size_t /* align */) override {
DEBUG_PRINT(p << " " << sz);
HAZPTR_DEBUG_PRINT(p << " " << sz);
free(p);
}
};
......@@ -40,12 +40,12 @@ class Node2 : public hazptr_obj_base<Node2, void (*)(Node2*)> {
};
inline void mineReclaimFnFree(Node2* p) {
DEBUG_PRINT(p << " " << sizeof(Node2));
HAZPTR_DEBUG_PRINT(p << " " << sizeof(Node2));
free(p);
}
inline void mineReclaimFnDelete(Node2* p) {
DEBUG_PRINT(p << " " << sizeof(Node2));
HAZPTR_DEBUG_PRINT(p << " " << sizeof(Node2));
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