[Tile-serving] [openstreetmap/osm2pgsql] limit the number of buffers that are in the copy queue (#960)

mmd notifications at github.com
Tue Oct 15 06:01:12 UTC 2019


mmd-osm commented on this pull request.



> @@ -28,9 +28,18 @@ db_copy_thread_t::~db_copy_thread_t() { finish(); }
 void db_copy_thread_t::add_buffer(std::unique_ptr<db_cmd_t> &&buffer)
 {
     assert(m_worker.joinable()); // thread must not have been finished
-    std::unique_lock<std::mutex> lock(m_queue_mutex);
-    m_worker_queue.push_back(std::move(buffer));
-    m_queue_cond.notify_one();
+
+    for (;;) {
+        std::unique_lock<std::mutex> lock(m_queue_mutex);
+        if (m_worker_queue.size() >= db_cmd_copy_t::Max_buffers) {
+            m_queue_full_cond.wait(lock);

just checked how this is done in _c++ concurrency in action_. They use a lambda function for the condition variable wait method: https://github.com/anthonywilliams/ccia_code_samples/blob/master/listings/listing_4.1.cpp#L47 (code example is not about a bounded queue, it's just to show how they use condition variables throughout chapter 4).

-- 
You are receiving this because you are subscribed to this thread.
Reply to this email directly or view it on GitHub:
https://github.com/openstreetmap/osm2pgsql/pull/960#pullrequestreview-301667472
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.openstreetmap.org/pipermail/tile-serving/attachments/20191014/4a941a9b/attachment.html>


More information about the Tile-serving mailing list