File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -28,9 +28,18 @@ db_copy_thread_t::~db_copy_thread_t() { finish(); }
2828void db_copy_thread_t::add_buffer (std::unique_ptr<db_cmd_t > &&buffer)
2929{
3030 assert (m_worker.joinable ()); // thread must not have been finished
31- std::unique_lock<std::mutex> lock (m_queue_mutex);
32- m_worker_queue.push_back (std::move (buffer));
33- m_queue_cond.notify_one ();
31+
32+ for (;;) {
33+ std::unique_lock<std::mutex> lock (m_queue_mutex);
34+ if (m_worker_queue.size () >= db_cmd_copy_t ::Max_buffers) {
35+ m_queue_full_cond.wait (lock);
36+ continue ;
37+ }
38+
39+ m_worker_queue.push_back (std::move (buffer));
40+ m_queue_cond.notify_one ();
41+ break ;
42+ }
3443}
3544
3645void db_copy_thread_t::sync_and_wait ()
@@ -67,6 +76,7 @@ void db_copy_thread_t::worker_thread()
6776
6877 item = std::move (m_worker_queue.front ());
6978 m_worker_queue.pop_front ();
79+ m_queue_full_cond.notify_one ();
7080 }
7181
7282 switch (item->type ) {
Original file line number Diff line number Diff line change @@ -67,7 +67,7 @@ class db_cmd_t
6767
6868struct db_cmd_copy_t : public db_cmd_t
6969{
70- enum { Max_buf_size = 10 * 1024 * 1024 };
70+ enum { Max_buf_size = 10 * 1024 * 1024 , Max_buffers = 10 };
7171 // / Name of the target table for the copy operation
7272 std::shared_ptr<db_target_descr_t > target;
7373 // / Vector with object to delete before copying
@@ -141,6 +141,7 @@ class db_copy_thread_t
141141 std::thread m_worker;
142142 std::mutex m_queue_mutex;
143143 std::condition_variable m_queue_cond;
144+ std::condition_variable m_queue_full_cond;
144145 std::deque<std::unique_ptr<db_cmd_t >> m_worker_queue;
145146
146147 // Target for copy operation currently ongoing.
You can’t perform that action at this time.
0 commit comments