summaryrefslogtreecommitdiffstats
path: root/misc/thread_tools.h
diff options
context:
space:
mode:
authorwm4 <wm4@nowhere>2018-05-17 20:58:49 +0200
committerwm4 <wm4@nowhere>2018-05-24 19:56:35 +0200
commit31b78ad7fa97d8047b609c1647a273e72612d425 (patch)
treed6a5e960ac431eef46d01b440fd504b1ac1f1159 /misc/thread_tools.h
parent12bd4fe9abce797a3c98dc437579b163e0a8162a (diff)
downloadmpv-31b78ad7fa97d8047b609c1647a273e72612d425.tar.bz2
mpv-31b78ad7fa97d8047b609c1647a273e72612d425.tar.xz
misc: move mp_cancel from stream.c to thread_tools.c
It seems a bit inappropriate to have dumped this into stream.c, even if it's roughly speaking its main user. At least it made its way somewhat unfortunately to other components not related to the stream or demuxer layer at all. I'm too greedy to give this weird helper its own file, so dump it into thread_tools.c. Probably a somewhat pointless change.
Diffstat (limited to 'misc/thread_tools.h')
-rw-r--r--misc/thread_tools.h28
1 files changed, 28 insertions, 0 deletions
diff --git a/misc/thread_tools.h b/misc/thread_tools.h
index 54f396dead..a734ac85b0 100644
--- a/misc/thread_tools.h
+++ b/misc/thread_tools.h
@@ -37,3 +37,31 @@ void mp_waiter_wakeup(struct mp_waiter *waiter, uintptr_t value);
// wakeup (in parallel to mp_waiter).
// You still need to call mp_waiter_wait() to free resources.
bool mp_waiter_poll(struct mp_waiter *waiter);
+
+// Basically a binary semaphore that supports signaling the semaphore value to
+// a bunch of other complicated mechanisms (such as wakeup pipes). It was made
+// for aborting I/O and thus has according naming.
+struct mp_cancel;
+
+struct mp_cancel *mp_cancel_new(void *talloc_ctx);
+
+// Request abort.
+void mp_cancel_trigger(struct mp_cancel *c);
+
+// Return whether the caller should abort.
+// For convenience, c==NULL is allowed.
+bool mp_cancel_test(struct mp_cancel *c);
+
+// Wait until the even is signaled. If the timeout (in seconds) expires, return
+// false. timeout==0 polls, timeout<0 waits forever.
+bool mp_cancel_wait(struct mp_cancel *c, double timeout);
+
+// Restore original state. (Allows reusing a mp_cancel.)
+void mp_cancel_reset(struct mp_cancel *c);
+
+// win32 "Event" HANDLE that indicates the current mp_cancel state.
+void *mp_cancel_get_event(struct mp_cancel *c);
+
+// The FD becomes readable if mp_cancel_test() would return true.
+// Don't actually read from it, just use it for poll().
+int mp_cancel_get_fd(struct mp_cancel *c);