This is the first time I hear about memgraph, its really interesting because I'm beginning a project that involves the analysis of some large graphs.
Sometimes, before using a lib, I dig into the GitHub repo. So here, I viewed their implementation of a ring buffer (memgraph/src/data_structures/ring_buffer.hpp).
I was surprised with what I found, especially the sleep after adding an element and the loop just before a spin-lock. Not sure, if this is a good implementation, I hope if a more knowledgable person could explain to me this piece of code.
```
template <typename... TArgs>
void emplace(TArgs &&...args) {
while (true) {
{
std::lock_guard<memgraph::utils::SpinLock> guard(lock_);
if (size_ < capacity_) {
buffer_[write_pos_++] = TElement(std::forward<TArgs>(args)...);
write_pos_ %= capacity_;
size_++;
return;
}
}
SPDLOG_WARN("RingBuffer full: worker waiting");
// Sleep time determined using tests/benchmark/ring_buffer.cpp
std::this_thread::sleep_for(std::chrono::microseconds(250));
}
}
```