summaryrefslogtreecommitdiffstats
path: root/misc/thread_tools.h
diff options
context:
space:
mode:
authorwm4 <wm4@nowhere>2018-05-17 21:20:26 +0200
committerwm4 <wm4@nowhere>2018-05-24 19:56:35 +0200
commita253c72dbb0fedf3b83f2f20f1f311c40551a6b1 (patch)
treeab6f4b51fad6380ae9c983db9d45f0a9e5bb451b /misc/thread_tools.h
parent782e4282841fae59d60b16ddfc00bb45cf40771e (diff)
downloadmpv-a253c72dbb0fedf3b83f2f20f1f311c40551a6b1.tar.bz2
mpv-a253c72dbb0fedf3b83f2f20f1f311c40551a6b1.tar.xz
thread_tools: unify mp_cancel POSIX/win32 paths, add features
The OS specifics are merged because the resulting ifdeffery is not much worse than the old ifdeffery, but the logic that is now shared is becoming more complex. Create all objects lazily. The intention is to make mp_cancel instances cheaper. POSIX pipes and win32 Events are pretty heavy weight, and are only needed in special situations. Add a mechanism to "chain" mp_cancel instances. Needed by the later commits for whatever reasons. Untested on win32.
Diffstat (limited to 'misc/thread_tools.h')
-rw-r--r--misc/thread_tools.h17
1 files changed, 17 insertions, 0 deletions
diff --git a/misc/thread_tools.h b/misc/thread_tools.h
index a734ac85b0..2198181e6c 100644
--- a/misc/thread_tools.h
+++ b/misc/thread_tools.h
@@ -59,6 +59,23 @@ 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);
+// Add a callback to invoke when mp_cancel gets triggered. If it's already
+// triggered, call it from mp_cancel_add_cb() directly. May be called multiple
+// times even if the trigger state changes; not called if it resets. In all
+// cases, this may be called with internal locks held (either in mp_cancel, or
+// other locks held by whoever calls mp_cancel_trigger()).
+// There is only one callback. Create a slave mp_cancel to get a private one.
+void mp_cancel_set_cb(struct mp_cancel *c, void (*cb)(void *ctx), void *ctx);
+
+// If c gets triggered, automatically trigger slave. Trying to add a slave more
+// than once or to multiple parents is undefined behavior.
+// The parent mp_cancel must remain valid until the slave is manually removed
+// or destroyed. Destroying a mp_cancel that still has slaves is an error.
+void mp_cancel_add_slave(struct mp_cancel *c, struct mp_cancel *slave);
+
+// Undo mp_cancel_add_slave(). Ignores never added slaves for easier cleanup.
+void mp_cancel_remove_slave(struct mp_cancel *c, struct mp_cancel *slave);
+
// win32 "Event" HANDLE that indicates the current mp_cancel state.
void *mp_cancel_get_event(struct mp_cancel *c);