Thread (39 messages) flat view 39 messages, 3 authors, 2016-06-15
STALE3748d

[PATCH 3/4] run-command: allow aborting async code prematurely

From: Jeff King <hidden>
Date: 2016-06-15 22:50:57
Subsystem: the rest · Maintainer: Linus Torvalds

We provide only two abstract promitives for async code:
start and finish. Where "finish" means to wait until the
async code tells us it is done. However, it may also be
useful for us to to tell the async code to abort right away,
because whatever it was doing is no longer useful.

For a separate process, we just kill() it. For Windows, we
need to do whatever the equivalent to pthread_cancel is.

Signed-off-by: Jeff King <redacted>
---
 run-command.c |   10 ++++++++++
 run-command.h |    1 +
 2 files changed, 11 insertions(+), 0 deletions(-)
diff --git a/run-command.c b/run-command.c
index 258c880..f179d2a 100644
--- a/run-command.c
+++ b/run-command.c
@@ -439,6 +439,16 @@ int finish_async(struct async *async)
 	return ret;
 }
 
+void abort_async(struct async *async)
+{
+#ifndef WIN32
+	kill(async->pid, 15);
+#else
+	/* no clue */
+#endif
+	finish_async(async);
+}
+
 int run_hook(const char *index_file, const char *name, ...)
 {
 	struct child_process hook;
diff --git a/run-command.h b/run-command.h
index 65ccb1c..df2c736 100644
--- a/run-command.h
+++ b/run-command.h
@@ -83,5 +83,6 @@ struct async {
 
 int start_async(struct async *async);
 int finish_async(struct async *async);
+void abort_async(struct async *async);
 
 #endif
-- 
1.7.4.13.g8566c
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help