From: Brian Norris Date: Thu, 11 Oct 2012 23:40:05 +0000 (-0700) Subject: williams-queue: fixup header X-Git-Tag: pldi2013~34 X-Git-Url: http://plrg.eecs.uci.edu/git/?p=model-checker-benchmarks.git;a=commitdiff_plain;h=52533e63ca15fb03eebc3fa838d274f1943366dc;hp=adc372d8af13fdc07eba357f0c6de4319dbfce10;ds=sidebyside williams-queue: fixup header 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 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::lock_free_queue()': williams-queue.cc:(.text._ZN15lock_free_queueIiEC2Ev[_ZN15lock_free_queueIiEC5Ev]+0x92): undefined reference to `std::atomic::counted_node_ptr>::load(std::memory_order) const' ... collect2: ld returned 1 exit status --- diff --git a/williams-queue/williams-queue.h b/williams-queue/williams-queue.h index fdf8337..36633db 100644 --- a/williams-queue/williams-queue.h +++ b/williams-queue/williams-queue.h @@ -26,22 +26,7 @@ private: 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; - } - } -private: struct counted_node_ptr { int external_count; @@ -66,8 +51,9 @@ private: 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; } void release_ref() { @@ -164,6 +150,23 @@ private: 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 new_data(new T(new_value));