diff --git a/core/src/lib/bnet_server_tcp.cc b/core/src/lib/bnet_server_tcp.cc index 6c571e9a21a..9bdb8df19f5 100644 --- a/core/src/lib/bnet_server_tcp.cc +++ b/core/src/lib/bnet_server_tcp.cc @@ -106,7 +106,7 @@ static void CleanupBnetThreadServerTcp(alist* sockfds, ThreadList& thread_list) } if (!thread_list.WaitUntilThreadListIsEmpty()) { - Emsg1(M_ERROR, 0, _("Could not destroy client queue.\n")); + Emsg1(M_ERROR, 0, _("Could not destroy thread list.\n")); } Dmsg0(100, "CleanupBnetThreadServerTcp: finish\n"); } @@ -395,8 +395,8 @@ void BnetThreadServerTcp( memset(&bs->peer_addr, 0, sizeof(bs->peer_addr)); memcpy(&bs->client_addr, &cli_addr, sizeof(bs->client_addr)); - if (!thread_list.CreateAndAddNewThread(config, (void*)bs)) { - Jmsg1(NULL, M_ABORT, 0, _("Could not add job to client queue.\n")); + if (!thread_list.CreateAndAddNewThread(config, bs)) { + Jmsg1(NULL, M_ABORT, 0, _("Could not add thread to list.\n")); } } } diff --git a/core/src/lib/thread_list.cc b/core/src/lib/thread_list.cc index ec4946d6033..da6cfa5d1e8 100644 --- a/core/src/lib/thread_list.cc +++ b/core/src/lib/thread_list.cc @@ -134,7 +134,6 @@ bool ThreadList::CreateAndAddNewThread(ConfigurationParser* config, void* data) std::lock_guard l(impl_->thread_list_mutex_); - int success = false; if (impl_->thread_list_.size() < impl_->maximum_thread_count_) { ThreadListItem* item = new ThreadListItem; item->data_ = data; @@ -145,9 +144,9 @@ bool ThreadList::CreateAndAddNewThread(ConfigurationParser* config, void* data) item->WorkerThread_.detach(); impl_->thread_list_.insert(item); - success = true; + return true; } - return success; + return false; } -std::size_t ThreadList::GetSize() { return impl_->thread_list_.size(); } +std::size_t ThreadList::GetSize() const { return impl_->thread_list_.size(); } diff --git a/core/src/lib/thread_list.h b/core/src/lib/thread_list.h index 1eba73660da..de2935ad545 100644 --- a/core/src/lib/thread_list.h +++ b/core/src/lib/thread_list.h @@ -23,9 +23,6 @@ #define BAREOS_LIB_THREAD_LIST_H_ 1 #include -#include -#include -#include class ConfigurationParser; struct ThreadListPrivate; @@ -44,7 +41,7 @@ class ThreadList { bool CreateAndAddNewThread(ConfigurationParser* config, void* data); bool WaitUntilThreadListIsEmpty(); - std::size_t GetSize(); + std::size_t GetSize() const; ThreadList(const ThreadList& ohter) = delete; ThreadList(const ThreadList&& ohter) = delete; diff --git a/core/src/stored/ndmp_tape.cc b/core/src/stored/ndmp_tape.cc index 2a427ec80b9..b5626ba4453 100644 --- a/core/src/stored/ndmp_tape.cc +++ b/core/src/stored/ndmp_tape.cc @@ -1465,10 +1465,9 @@ extern "C" void* ndmp_thread_server(void* arg) memcpy(&new_handle->client_addr, &cli_addr, sizeof(new_handle->client_addr)); - if (!ntsa->thread_list->CreateAndAddNewThread(my_config, - (void*)new_handle)) { + if (!ntsa->thread_list->CreateAndAddNewThread(my_config, new_handle)) { Jmsg1(NULL, M_ABORT, 0, - _("Could not add job to ndmp client queue.\n")); + _("Could not add job to ndmp thread list.\n")); } } } @@ -1483,14 +1482,8 @@ extern "C" void* ndmp_thread_server(void* arg) fd_ptr = (s_sockfd*)sockfds.next(); } - /* - * Stop work queue thread - */ if (!ntsa->thread_list->WaitUntilThreadListIsEmpty()) { - BErrNo be; - be.SetErrno(status); - Emsg1(M_FATAL, 0, _("Could not destroy ndmp client queue: ERR=%s\n"), - be.bstrerror()); + Emsg1(M_FATAL, 0, _("Could not destroy ndmp thread list.\n")); } return NULL; diff --git a/core/src/tests/thread_list.cc b/core/src/tests/thread_list.cc index 25e208a4dda..236918afb39 100644 --- a/core/src/tests/thread_list.cc +++ b/core/src/tests/thread_list.cc @@ -80,17 +80,17 @@ static void* ShutdownCallback(void* data) return nullptr; } -static constexpr int maximim_allowed_thread_count = 10; +static constexpr int maximum_allowed_thread_count = 10; static constexpr int try_to_start_thread_count = 11; TEST(thread_list, thread_list_startup_and_shutdown) { std::unique_ptr t(std::make_unique()); - t->Init(maximim_allowed_thread_count, ThreadHandler, ShutdownCallback); + t->Init(maximum_allowed_thread_count, ThreadHandler, ShutdownCallback); for (int i = 0; i < try_to_start_thread_count; i++) { - std::unique_ptr wc(std::make_unique()); + auto wc(std::make_unique()); if (t->CreateAndAddNewThread(nullptr, wc.get())) { list_of_wait_conditions.push_back(std::move(wc)); } @@ -103,5 +103,5 @@ TEST(thread_list, thread_list_startup_and_shutdown) EXPECT_EQ(c.get()->GetStatus(), WaitCondition::Status::kSuccess); } - EXPECT_EQ(counter, maximim_allowed_thread_count); + EXPECT_EQ(counter, maximum_allowed_thread_count); }