Skip to content

Commit

Permalink
break loop in unreportedAdminThread_ if the sever being stopped
Browse files Browse the repository at this point in the history
  • Loading branch information
liwenhui-soul committed Oct 8, 2021
1 parent c1933dc commit 90d02b3
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/storage/admin/AdminTaskManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ void AdminTaskManager::handleUnreportedTasks() {
while (true) {
std::unique_lock<std::mutex> lk(unreportedMutex_);
if (!ifAny) unreportedCV_.wait(lk);
if (stopped_.load(std::memory_order_acquire)) break;
ifAny = false;
std::unique_ptr<kvstore::KVIterator> iter;
auto kvRet = env_->adminStore_->scan(&iter);
Expand Down Expand Up @@ -119,6 +120,7 @@ void AdminTaskManager::handleUnreportedTasks() {
}
env_->adminStore_->multiRemove(keys);
}
LOG(INFO) << "Unreported-Admin-Thread stopped";
}));
}

Expand Down Expand Up @@ -177,6 +179,9 @@ void AdminTaskManager::shutdown() {
}

pool_->join();
stopped_.store(true, std::memory_order_release);
notifyReporting();
if (unreportedAdminThread_ != nullptr) unreportedAdminThread_->join();
LOG(INFO) << "exit AdminTaskManager::shutdown()";
}

Expand Down
1 change: 1 addition & 0 deletions src/storage/admin/AdminTaskManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ class AdminTaskManager {
std::unique_ptr<std::thread> unreportedAdminThread_;
std::mutex unreportedMutex_;
std::condition_variable unreportedCV_;
std::atomic<bool> stopped_ = false;
};

} // namespace storage
Expand Down

0 comments on commit 90d02b3

Please sign in to comment.