We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
struct LinkedList : public BufferBase { LinkedList() : m_head(nullptr) { } struct Item { Item(NanoLogLine && logline_) : next(nullptr), logline(std::move(logline_)) {} std::atomic < Item * > next; NanoLogLine logline; }; void push(NanoLogLine && logline) override { Item * item = new Item(std::move(logline)); Item * head = m_head.load(std::memory_order_relaxed); do { item->next = head; } while(!m_head.compare_exchange_weak(head, item, std::memory_order_release, std::memory_order_relaxed)); } bool try_pop(NanoLogLine & logline) override { if (!m_read_buffer.empty()) { logline = std::move(m_read_buffer.front()); m_read_buffer.pop_front(); return true; } Item * head = get_current_head(); while (head != nullptr) { Item * next = head->next.load(std::memory_order_acquire); m_read_buffer.push_front(std::move(head->logline)); delete head; head = next; }; if (m_read_buffer.empty()) return false; else return try_pop(logline); } Item * get_current_head() { Item * current_head = m_head.load(std::memory_order_acquire); while (!m_head.compare_exchange_weak(current_head, nullptr, std::memory_order_release, std::memory_order_relaxed)); return current_head; } private: std::atomic < Item * > m_head; std::deque < NanoLogLine > m_read_buffer; };
The text was updated successfully, but these errors were encountered:
any benchmark ?
Sorry, something went wrong.
Latency numbers were pretty much same with linked list so I did not pursue this further...
No branches or pull requests
The text was updated successfully, but these errors were encountered: