aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThomas White <taw@physics.org>2019-10-16 16:42:29 +0200
committerThomas White <taw@physics.org>2019-10-17 10:03:41 +0200
commit96861c596671a185b1e2fc24c60d6fbdf6ee865d (patch)
tree66240f9978d094603bb7849df3d0a2857eecc2cf
parentbff069f97ad705b44e0432f93597a874d19baa8a (diff)
indexamajig: Shut down gracefully after failed image load
-rw-r--r--src/im-sandbox.c18
-rw-r--r--src/im-sandbox.h1
-rw-r--r--src/indexamajig.c6
-rw-r--r--src/process_image.c10
4 files changed, 26 insertions, 9 deletions
diff --git a/src/im-sandbox.c b/src/im-sandbox.c
index 8097c273..521cbf79 100644
--- a/src/im-sandbox.c
+++ b/src/im-sandbox.c
@@ -414,8 +414,12 @@ static int run_work(const struct index_args *iargs, Stream *st,
/* Get the event from the queue */
set_last_task(sb->shared->last_task[cookie], "read_queue");
pthread_mutex_lock(&sb->shared->queue_lock);
- if ( (sb->shared->n_events==0) && (sb->shared->no_more) ) {
- /* Queue is empty and no more coming, so exit */
+ if ( ((sb->shared->n_events==0) && (sb->shared->no_more))
+ || (sb->shared->should_shutdown) )
+ {
+ /* Queue is empty and no more are coming,
+ * or another process has initiated a shutdown.
+ * Either way, it's time to get out of here. */
pthread_mutex_unlock(&sb->shared->queue_lock);
allDone = 1;
continue;
@@ -1112,6 +1116,7 @@ int create_sandbox(struct index_args *iargs, int n_proc, char *prefix,
sb->shared->n_hits = 0;
sb->shared->n_hadcrystals = 0;
sb->shared->n_crystals = 0;
+ sb->shared->should_shutdown = 0;
/* Set up semaphore to control work queue */
snprintf(semname_q, 64, "indexamajig-q%i", getpid());
@@ -1198,6 +1203,12 @@ int create_sandbox(struct index_args *iargs, int n_proc, char *prefix,
time_accounts_set(taccs, TACC_ENDCHECK);
pthread_mutex_lock(&sb->shared->queue_lock);
if ( sb->shared->no_more && (sb->shared->n_events == 0) ) allDone = 1;
+ if ( sb->shared->should_shutdown ) {
+ /* Worker process requested immediate shutdown */
+ allDone = 1;
+ sb->shared->n_events = 0;
+ sb->shared->no_more = 1;
+ }
pthread_mutex_unlock(&sb->shared->queue_lock);
} while ( !allDone );
@@ -1251,7 +1262,8 @@ int create_sandbox(struct index_args *iargs, int n_proc, char *prefix,
free(sb->pids);
try_status(sb, 1);
- r = sb->shared->n_processed;
+ r = (sb->shared->n_processed == 0);
+ if ( sb->shared->should_shutdown ) r = 1;
delete_temporary_folder(sb->tmpdir, n_proc);
diff --git a/src/im-sandbox.h b/src/im-sandbox.h
index 3acd62db..400af333 100644
--- a/src/im-sandbox.h
+++ b/src/im-sandbox.h
@@ -75,6 +75,7 @@ struct sb_shm
int n_hits;
int n_hadcrystals;
int n_crystals;
+ int should_shutdown;
};
extern char *create_tempdir(const char *temp_location);
diff --git a/src/indexamajig.c b/src/indexamajig.c
index aa316caf..d52eb3cf 100644
--- a/src/indexamajig.c
+++ b/src/indexamajig.c
@@ -1073,9 +1073,5 @@ int main(int argc, char *argv[])
close_stream(st);
cleanup_indexing(args.iargs.ipriv);
- if ( r ) {
- return 0;
- } else {
- return 1; /* No patterns processed */
- }
+ return r;
}
diff --git a/src/process_image.c b/src/process_image.c
index f28952bc..dbb9bc2e 100644
--- a/src/process_image.c
+++ b/src/process_image.c
@@ -223,7 +223,15 @@ void process_image(const struct index_args *iargs, struct pattern_args *pargs,
} else {
if ( file_wait_open_read(sb_shared, &image, taccs, last_task,
iargs->wait_for_file, cookie,
- &imfile) ) return;
+ &imfile) )
+ {
+ if ( iargs->wait_for_file != 0 ) {
+ pthread_mutex_lock(&sb_shared->totals_lock);
+ sb_shared->should_shutdown = 1;
+ pthread_mutex_unlock(&sb_shared->totals_lock);
+ }
+ return;
+ }
}
image.bw = iargs->beam->bandwidth;