summary |
shortlog |
log |
commit | commitdiff |
tree
raw |
patch |
inline | side by side (from parent 1:
adc372d)
Move the constructor lower, so that member definitions appear earlier
than it in the class definition.
Also, don't assign to members of the atomic structure directly; use a
temporary struct then assign the whole struct.
Still won't compile. Seeing linker errors, probably due to the fact that
this code uses a nonstandrad atomic template:
std::atomic<counted_node_ptr>
Where counted_node_ptr is a struct with int and pointer members. Thus,
it has size of at least 96 bytes (32+64) and so probably isn't really
supported by atomics... I'm not sure where the author came up with this.
$ g++ williams-queue.cc --std=c++0x
/tmp/ccPQgiJC.o: In function `lock_free_queue<int>::lock_free_queue()': williams-queue.cc:(.text._ZN15lock_free_queueIiEC2Ev[_ZN15lock_free_queueIiEC5Ev]+0x92): undefined reference to `std::atomic<lock_free_queue<int>::counted_node_ptr>::load(std::memory_order) const'
...
collect2: ld returned 1 exit status
head.store(old_head->next);
return old_head;
}
head.store(old_head->next);
return old_head;
}
-public:
- lock_free_queue():
- head(new node),tail(head.load())
- {}
- // lock_free_queue(const lock_free_queue& other)=delete;
- // lock_free_queue& operator=(const lock_free_queue& other)=delete;
- ~lock_free_queue()
- {
- while(node* const old_head=head.load())
- {
- head.store(old_head->next);
- delete old_head;
- }
- }
struct counted_node_ptr
{
int external_count;
struct counted_node_ptr
{
int external_count;
new_count.internal_count=0;
new_count.external_counters=2;
count.store(new_count);
new_count.internal_count=0;
new_count.external_counters=2;
count.store(new_count);
- next.ptr=nullptr;
- next.external_count=0;
+
+ counted_node_ptr emptynode = {0, nullptr};
+ next = emptynode;
current_tail_ptr->release_ref();
}
public:
current_tail_ptr->release_ref();
}
public:
+ lock_free_queue()
+ {
+ counted_node_ptr newnode = {0, new node};
+ head = newnode;
+ tail = head.load();
+ }
+ // lock_free_queue(const lock_free_queue& other)=delete;
+ // lock_free_queue& operator=(const lock_free_queue& other)=delete;
+ ~lock_free_queue()
+ {
+ while(node* const old_head=head.load())
+ {
+ head.store(old_head->next);
+ delete old_head;
+ }
+ }
+
void push(T new_value)
{
std::unique_ptr<T> new_data(new T(new_value));
void push(T new_value)
{
std::unique_ptr<T> new_data(new T(new_value));