Skip to content

Commit

Permalink
cleanup
Browse files Browse the repository at this point in the history
- corrected typos
- removed or corrected log messages
- removed a unneeded variable
  • Loading branch information
franku committed Sep 2, 2019
1 parent 16bea07 commit 30e9c2b
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 25 deletions.
6 changes: 3 additions & 3 deletions core/src/lib/bnet_server_tcp.cc
Expand Up @@ -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");
}
Expand Down Expand Up @@ -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"));
}
}
}
Expand Down
7 changes: 3 additions & 4 deletions core/src/lib/thread_list.cc
Expand Up @@ -134,7 +134,6 @@ bool ThreadList::CreateAndAddNewThread(ConfigurationParser* config, void* data)

std::lock_guard<std::mutex> l(impl_->thread_list_mutex_);

int success = false;
if (impl_->thread_list_.size() < impl_->maximum_thread_count_) {
ThreadListItem* item = new ThreadListItem;
item->data_ = data;
Expand All @@ -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(); }
5 changes: 1 addition & 4 deletions core/src/lib/thread_list.h
Expand Up @@ -23,9 +23,6 @@
#define BAREOS_LIB_THREAD_LIST_H_ 1

#include <functional>
#include <condition_variable>
#include <mutex>
#include <set>

class ConfigurationParser;
struct ThreadListPrivate;
Expand All @@ -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;
Expand Down
13 changes: 3 additions & 10 deletions core/src/stored/ndmp_tape.cc
Expand Up @@ -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"));
}
}
}
Expand All @@ -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;
Expand Down
8 changes: 4 additions & 4 deletions core/src/tests/thread_list.cc
Expand Up @@ -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<ThreadList> t(std::make_unique<ThreadList>());

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<WaitCondition> wc(std::make_unique<WaitCondition>());
auto wc(std::make_unique<WaitCondition>());
if (t->CreateAndAddNewThread(nullptr, wc.get())) {
list_of_wait_conditions.push_back(std::move(wc));
}
Expand All @@ -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);
}

0 comments on commit 30e9c2b

Please sign in to comment.