Fix copyright lines
[folly.git] / folly / experimental / hazptr / example / LockFreeLIFO.h
index 397bdcc789bd8d01b3dfc90d018f6b1cf11158cd..d7b0247fb5199fabacd66691f8920ee066a20085 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright 2016 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.
@@ -49,20 +49,28 @@ class LockFreeLIFO {
   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;
-    Node* pnode;
-    while (true) {
-      if ((pnode = head_.load()) == nullptr) return false;
-      if (!hptr.protect(pnode, head_)) continue;
+    hazptr_holder hptr;
+    Node* pnode = head_.load();
+    do {
+      if (pnode == nullptr) {
+        return false;
+      }
+      if (!hptr.try_protect(pnode, head_)) {
+        continue;
+      }
       auto next = pnode->next_;
-      if (head_.compare_exchange_weak(pnode, next)) break;
-    }
-    hptr.clear();
+      if (head_.compare_exchange_weak(pnode, next)) {
+        break;
+      }
+    } while (true);
+    hptr.reset();
     val = pnode->value_;
     pnode->retire();
     return true;
@@ -72,5 +80,5 @@ class LockFreeLIFO {
   std::atomic<Node*> head_ = {nullptr};
 };
 
-} // namespace folly {
-} // namespace hazptr {
+} // namespace hazptr
+} // namespace folly