add original source
This commit is contained in:
20
source/listing_7.14.cpp
Normal file
20
source/listing_7.14.cpp
Normal file
@@ -0,0 +1,20 @@
|
||||
void push(T new_value)
|
||||
{
|
||||
std::unique_ptr<T> new_data(new T(new_value));
|
||||
counted_node_ptr new_next;
|
||||
new_next.ptr=new node;
|
||||
new_next.external_count=1;
|
||||
for(;;)
|
||||
{
|
||||
node* const old_tail=tail.load();
|
||||
T* old_data=nullptr;
|
||||
if(old_tail->data.compare_exchange_strong(
|
||||
old_data,new_data.get()))
|
||||
{
|
||||
old_tail->next=new_next;
|
||||
tail.store(new_next.ptr);
|
||||
new_data.release();
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user