Commit b9765f33 authored by Dominik Charousset's avatar Dominik Charousset

cleaned up code in producer_consumer_list

parent fb372b13
......@@ -116,18 +116,6 @@ class producer_consumer_list {
std::atomic<bool> m_consumer_lock;
std::atomic<bool> m_producer_lock;
void push_impl(node* tmp) {
// acquire exclusivity
while (m_producer_lock.exchange(true)) {
std::this_thread::yield();
}
// publish & swing last forward
m_last->next = tmp;
m_last = tmp;
// release exclusivity
m_producer_lock = false;
}
public:
producer_consumer_list() {
......@@ -146,7 +134,16 @@ class producer_consumer_list {
inline void push_back(pointer value) {
assert(value != nullptr);
push_impl(new node(value));
node* tmp = new node(value);
// acquire exclusivity
while (m_producer_lock.exchange(true)) {
std::this_thread::yield();
}
// publish & swing last forward
m_last->next = tmp;
m_last = tmp;
// release exclusivity
m_producer_lock = false;
}
// returns nullptr on failure
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment