mirror of
https://github.com/privacore/open-source-search-engine.git
synced 2025-07-17 02:56:07 -04:00
Cancel all queued jobs when shutting down
This commit is contained in:
@ -316,6 +316,7 @@ public:
|
||||
bool are_new_jobs_allowed() const {
|
||||
return new_jobs_allowed && !no_threads;
|
||||
}
|
||||
void cancel_all_jobs_for_shutdown();
|
||||
|
||||
unsigned num_queued_jobs() const;
|
||||
|
||||
@ -530,6 +531,31 @@ bool JobScheduler_impl::is_reading_file(const BigFile *bf)
|
||||
}
|
||||
|
||||
|
||||
void JobScheduler_impl::cancel_all_jobs_for_shutdown() {
|
||||
ScopedLock sl(mtx);
|
||||
while(!cpu_job_queue.empty()) {
|
||||
exit_set.push_back(std::make_pair(cpu_job_queue.back(),job_exit_program_exit));
|
||||
cpu_job_queue.pop_back();
|
||||
}
|
||||
while(!io_job_queue.empty()) {
|
||||
exit_set.push_back(std::make_pair(io_job_queue.back(),job_exit_program_exit));
|
||||
io_job_queue.pop_back();
|
||||
}
|
||||
while(!external_job_queue.empty()) {
|
||||
exit_set.push_back(std::make_pair(external_job_queue.back(),job_exit_program_exit));
|
||||
external_job_queue.pop_back();
|
||||
}
|
||||
while(!file_meta_job_queue.empty()) {
|
||||
exit_set.push_back(std::make_pair(file_meta_job_queue.back(),job_exit_program_exit));
|
||||
file_meta_job_queue.pop_back();
|
||||
}
|
||||
while(!merge_job_queue.empty()) {
|
||||
exit_set.push_back(std::make_pair(merge_job_queue.back(),job_exit_program_exit));
|
||||
merge_job_queue.pop_back();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
unsigned JobScheduler_impl::num_queued_jobs() const
|
||||
{
|
||||
@ -721,6 +747,12 @@ bool JobScheduler::are_new_jobs_allowed() const
|
||||
}
|
||||
|
||||
|
||||
void JobScheduler::cancel_all_jobs_for_shutdown() {
|
||||
if(impl)
|
||||
impl->cancel_all_jobs_for_shutdown();
|
||||
}
|
||||
|
||||
|
||||
unsigned JobScheduler::num_queued_jobs() const
|
||||
{
|
||||
if(impl)
|
||||
|
@ -111,6 +111,8 @@ public:
|
||||
void disallow_new_jobs();
|
||||
bool are_new_jobs_allowed() const;
|
||||
|
||||
void cancel_all_jobs_for_shutdown();
|
||||
|
||||
unsigned num_queued_jobs() const;
|
||||
|
||||
void cleanup_finished_jobs();
|
||||
|
@ -705,6 +705,8 @@ bool Process::shutdown2() {
|
||||
RdbBase::finalizeGlobalIndexThread();
|
||||
finalizeMsg4IncomingThread();
|
||||
|
||||
g_jobScheduler.cancel_all_jobs_for_shutdown();
|
||||
|
||||
static bool s_printed = false;
|
||||
|
||||
// wait for all threads to return
|
||||
|
Reference in New Issue
Block a user