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 aa76a96
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
12 changes: 10 additions & 2 deletions src/storage/admin/AdminTaskManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,10 @@ void AdminTaskManager::handleUnreportedTasks() {
if (env_ == nullptr) return;
unreportedAdminThread_.reset(new std::thread([this] {
bool ifAny = true;
std::unique_lock<std::mutex> lk(unreportedMutex_);
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 Expand Up @@ -308,7 +313,10 @@ void AdminTaskManager::runSubTask(TaskHandle handle) {
}
}

void AdminTaskManager::notifyReporting() { unreportedCV_.notify_one(); }
void AdminTaskManager::notifyReporting() {
std::unique_lock<std::mutex> lk(unreportedMutex_);
unreportedCV_.notify_one();
}

bool AdminTaskManager::isFinished(JobID jobID, TaskID taskID) {
auto iter = tasks_.find(std::make_pair(jobID, taskID));
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 aa76a96

Please sign in to comment.