Skip to content

Commit

Permalink
Merge pull request #298 from bareos/dev/franku/master/thread_list_fixup
Browse files Browse the repository at this point in the history
thread_list: improved list access
  • Loading branch information
arogge committed Oct 9, 2019
2 parents b298e64 + f90662a commit 681d9b8
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 5 deletions.
8 changes: 5 additions & 3 deletions core/src/lib/thread_list.cc
Original file line number Diff line number Diff line change
Expand Up @@ -130,8 +130,6 @@ static void WorkerThread(std::unique_ptr<ThreadListItem> item, ThreadList* t)

bool ThreadList::CreateAndAddNewThread(ConfigurationParser* config, void* data)
{
if (!impl_) { return false; }

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

if (impl_->thread_list_.size() < impl_->maximum_thread_count_) {
Expand All @@ -149,4 +147,8 @@ bool ThreadList::CreateAndAddNewThread(ConfigurationParser* config, void* data)
return false;
}

std::size_t ThreadList::GetSize() const { return impl_->thread_list_.size(); }
std::size_t ThreadList::Size() const
{
std::lock_guard<std::mutex> l(impl_->thread_list_mutex_);
return impl_->thread_list_.size();
}
2 changes: 1 addition & 1 deletion core/src/lib/thread_list.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ class ThreadList {

bool CreateAndAddNewThread(ConfigurationParser* config, void* data);
bool WaitUntilThreadListIsEmpty();
std::size_t GetSize() const;
std::size_t Size() const;

ThreadList(const ThreadList& ohter) = delete;
ThreadList(const ThreadList&& ohter) = delete;
Expand Down
2 changes: 1 addition & 1 deletion core/src/tests/thread_list.cc
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ TEST(thread_list, thread_list_startup_and_shutdown)

t->WaitUntilThreadListIsEmpty();

EXPECT_EQ(t->GetSize(), 0);
EXPECT_EQ(t->Size(), 0);
for (const auto& c : list_of_wait_conditions) {
EXPECT_EQ(c.get()->GetStatus(), WaitCondition::Status::kSuccess);
}
Expand Down

0 comments on commit 681d9b8

Please sign in to comment.