/*
- * Copyright 2017 Facebook, Inc.
+ * Copyright 2016-present Facebook, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
void push(T val) {
DEBUG_PRINT(this);
auto pnode = new Node(val, head_.load());
- while (!head_.compare_exchange_weak(pnode->next_, pnode));
+ while (!head_.compare_exchange_weak(pnode->next_, pnode)) {
+ ;
+ }
}
bool pop(T& val) {
DEBUG_PRINT(this);
- hazptr_owner<Node> hptr;
+ hazptr_holder hptr;
Node* pnode = head_.load();
do {
- if (pnode == nullptr)
+ if (pnode == nullptr) {
return false;
- if (!hptr.try_protect(pnode, head_))
+ }
+ if (!hptr.try_protect(pnode, head_)) {
continue;
+ }
auto next = pnode->next_;
- if (head_.compare_exchange_weak(pnode, next)) break;
+ if (head_.compare_exchange_weak(pnode, next)) {
+ break;
+ }
} while (true);
- hptr.clear();
+ hptr.reset();
val = pnode->value_;
pnode->retire();
return true;
std::atomic<Node*> head_ = {nullptr};
};
-} // namespace folly {
-} // namespace hazptr {
+} // namespace hazptr
+} // namespace folly