diff options
author | Sergey Poznyakoff <gray@gnu.org.ua> | 2012-12-24 08:50:18 +0200 |
---|---|---|
committer | Sergey Poznyakoff <gray@gnu.org.ua> | 2012-12-24 08:50:18 +0200 |
commit | 633512c033c129a80a11a86ec85037fb2d2babf5 (patch) | |
tree | 7f1c0810110518f530237636dda7d9f2f39ba818 /src/job.c | |
parent | 0077bc419d34a0341f978fc0e2d5cba8d35d4b28 (diff) | |
download | wydawca-633512c033c129a80a11a86ec85037fb2d2babf5.tar.gz wydawca-633512c033c129a80a11a86ec85037fb2d2babf5.tar.bz2 |
Improve triplet queue handling.
Remove the expired and invalid triplets in the master process.
* src/job.c (job_queue_runner): Take estimated minimal
interval as an argument. Set timer even if no wake-up
is scheduled.
* src/net.c: Call triplet_sweep to sweep off expired
triplets and estimate minimal timeout for job_queue_runner.
* src/triplet.c: Link all registered triplets into a doubly-
linked list ordered by the triplet age, in descending order.
Use that list to estimate minimal timeout.
(triplet_list): New variable.
(triplet_timestamp, triplet_ttl)
(triplet_list_unlink,triplet_list_insert_before)
(triplet_list_ordered_insert): New static functions.
(register_file): Insert triplet into the list.
(triplet_expired_p): Take one argument. Obtain the ttl
from the associated spool. Fix condition.
(remove_triplet): Remove triplet from the list and symtab.
(triplet_sweep): New function.
(triplet_counter): Remove bad and expired triplets.
(triplet_remove_file): Call remove_triplet.
* src/wydawca.h (file_triplet) <next,prev>: New members.
(triplet_sweep): New proto.
(job_queue_runner): Change signature.
Diffstat (limited to 'src/job.c')
-rw-r--r-- | src/job.c | 117 |
1 files changed, 60 insertions, 57 deletions
@@ -291,84 +291,87 @@ print_status (struct job *job, int expect_term) } void -job_queue_runner () +job_queue_runner (time_t min_interval) { int status; struct job *job; time_t now = time (NULL); - time_t min_interval = 0; - if (!wakeup) - return; - wakeup = 0; - - for (;;) + if (wakeup) { - pid_t pid = waitpid ((pid_t)-1, &status, WNOHANG); - if (pid <= 0) - break; - for (job = queue; job; job = job->next) + wakeup = 0; + + for (;;) { - if ((job->state & STATE_ACTIVE) && job->pid == pid) + pid_t pid = waitpid ((pid_t)-1, &status, WNOHANG); + if (pid <= 0) + break; + for (job = queue; job; job = job->next) { - job->state &= ~STATE_ACTIVE; - job->state |= STATE_FINISHED; - job->exit_status = status; - jobcnt--; + if ((job->state & STATE_ACTIVE) && job->pid == pid) + { + job->state &= ~STATE_ACTIVE; + job->state |= STATE_FINISHED; + job->exit_status = status; + jobcnt--; + } } } - } - - for (job = queue; job;) - { - struct job *next = job->next; - if (job->state & STATE_FINISHED) + + for (job = queue; job;) { - print_status (job, 0); - if ((job->state &= ~STATE_FINISHED) == 0) + struct job *next = job->next; + if (job->state & STATE_FINISHED) { - if (WIFEXITED (job->exit_status) - && WEXITSTATUS (job->exit_status) == WYDAWCA_EX_AGAIN) + print_status (job, 0); + if ((job->state &= ~STATE_FINISHED) == 0) { - time_t interval = lock_timeout; - if (interval == 0) - interval = lock_expire_time; - /* Re-queue the job */ - job->state = STATE_QUEUED; - job->timestamp = now + interval; + if (WIFEXITED (job->exit_status) + && WEXITSTATUS (job->exit_status) == WYDAWCA_EX_AGAIN) + { + time_t interval = lock_timeout; + if (interval == 0) + interval = lock_expire_time; + /* Re-queue the job */ + job->state = STATE_QUEUED; + job->timestamp = now + interval; + } + else + { + job_remove (job); + free (job); + job = next; + continue; + } + } + } + + if (job->state == STATE_QUEUED) + { + if (job->timestamp >= now) + { + if (job_start (job)) + pause (); /* FIXME */ + now = time (NULL); } else { - job_remove (job); - free (job); - job = next; - continue; + time_t interval = job->timestamp - now; + if (min_interval == 0 || interval < min_interval) + min_interval = interval; } } + + job = next; } - - if (job->state == STATE_QUEUED) - { - if (job->timestamp >= now) - { - if (job_start (job)) - pause (); /* FIXME */ - now = time (NULL); - } - else - { - time_t interval = job->timestamp - now; - if (min_interval == 0 || interval < min_interval) - min_interval = interval; - } - } - - job = next; } - if (debug_level > 1) - logmsg (LOG_DEBUG, _("computed interval: %lu"), min_interval); - set_timer (min_interval); + if (min_interval) + { + if (debug_level > 1) + logmsg (LOG_DEBUG, _("computed interval: %lu"), min_interval); + set_timer (min_interval); + } } void |