Remove abstractions around job list

Directly access the job list without the intermediate job_iterator_t,
and remove functions that are ripe for abuse by modifying a local
enumeration of the same list instead of operating on the iterators
directly (e.g. proc.cpp iterates jobs, and mid-iteration calls
parser::job_remove(j) with the job (and not the iterator to the job),
causing an invisible invalidation of the pre-existing local iterators.
This commit is contained in:
Mahmoud Al-Qudsi
2018-12-30 21:25:16 -06:00
parent 0c5015d467
commit f8e0e0ef82
11 changed files with 87 additions and 150 deletions

View File

@@ -570,19 +570,6 @@ void parser_t::job_add(shared_ptr<job_t> job) {
this->my_job_list.push_front(std::move(job));
}
bool parser_t::job_remove(job_t *job) {
for (auto iter = my_job_list.begin(); iter != my_job_list.end(); ++iter) {
if (iter->get() == job) {
my_job_list.erase(iter);
return true;
}
}
debug(1, _(L"Job inconsistency"));
sanity_lose();
return false;
}
void parser_t::job_promote(job_t *job) {
job_list_t::iterator loc;
for (loc = my_job_list.begin(); loc != my_job_list.end(); ++loc) {
@@ -604,20 +591,17 @@ job_t *parser_t::job_get(job_id_t id) {
}
job_t *parser_t::job_get_from_pid(pid_t pid) const {
job_iterator_t jobs;
job_t *job;
pid_t pgid = getpgid(pid);
if (pgid == -1) {
return 0;
}
while ((job = jobs.next())) {
for (auto job : jobs()) {
if (job->pgid == pgid) {
for (const process_ptr_t &p : job->processes) {
if (p->pid == pid) {
return job;
return job.get();
}
}
}