Run clang-format
This commit is contained in:
@@ -1,25 +1,24 @@
|
||||
#include <atomic>
|
||||
#include <memory>
|
||||
|
||||
template<typename T>
|
||||
class lock_free_stack
|
||||
{
|
||||
template <typename T>
|
||||
class lock_free_stack {
|
||||
private:
|
||||
std::atomic<unsigned> threads_in_pop;
|
||||
void try_reclaim(node* old_head);
|
||||
std::atomic<unsigned> threads_in_pop;
|
||||
void try_reclaim(node* old_head);
|
||||
|
||||
public:
|
||||
std::shared_ptr<T> pop()
|
||||
{
|
||||
++threads_in_pop;
|
||||
node* old_head=head.load();
|
||||
while(old_head &&
|
||||
!head.compare_exchange_weak(old_head,old_head->next));
|
||||
std::shared_ptr<T> res;
|
||||
if(old_head)
|
||||
{
|
||||
res.swap(old_head->data);
|
||||
}
|
||||
try_reclaim(old_head);
|
||||
return res;
|
||||
std::shared_ptr<T> pop()
|
||||
{
|
||||
++threads_in_pop;
|
||||
node* old_head = head.load();
|
||||
while (old_head && !head.compare_exchange_weak(old_head, old_head->next))
|
||||
;
|
||||
std::shared_ptr<T> res;
|
||||
if (old_head) {
|
||||
res.swap(old_head->data);
|
||||
}
|
||||
try_reclaim(old_head);
|
||||
return res;
|
||||
}
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user