[vlc-devel] commit: Stub cancellation support ( Rémi Denis-Courmont )
git version control
git at videolan.org
Wed Aug 27 22:57:27 CEST 2008
vlc | branch: master | Rémi Denis-Courmont <rdenis at simphalempin.com> | Sat Jul 12 00:02:37 2008 +0300| [5a6312880481cc2f2cef82b141ddbd82b28825d9] | committer: Rémi Denis-Courmont
Stub cancellation support
> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=5a6312880481cc2f2cef82b141ddbd82b28825d9
---
include/vlc_threads.h | 16 ++++++++++++++++
src/libvlccore.sym | 1 +
src/misc/threads.c | 43 +++++++++++++++++++++++++++++++++++++++++++
3 files changed, 60 insertions(+), 0 deletions(-)
diff --git a/include/vlc_threads.h b/include/vlc_threads.h
index 9610793..c2dd303 100644
--- a/include/vlc_threads.h
+++ b/include/vlc_threads.h
@@ -589,6 +589,16 @@ static inline void barrier (void)
#endif
}
+#ifndef LIBVLC_USE_PTHREAD
+enum {
+ VLC_SAVE_CANCEL,
+ VLC_RESTORE_CANCEL,
+ VLC_TEST_CANCEL,
+};
+#endif
+
+VLC_EXPORT (void, vlc_control_cancel, (int cmd, ...));
+
/**
* Save the cancellation state and disable cancellation for the calling thread.
* This function must be called before entering a piece of code that is not
@@ -600,6 +610,8 @@ static inline void vlc_savecancel (int *p_state)
{
#if defined (LIBVLC_USE_PTHREAD)
(void) pthread_setcancelstate (PTHREAD_CANCEL_DISABLE, p_state);
+#else
+ vlc_control_cancel (VLC_SAVE_CANCEL, p_state);
#endif
}
@@ -612,6 +624,8 @@ static inline void vlc_restorecancel (int state)
{
#if defined (LIBVLC_USE_PTHREAD)
(void) pthread_setcancelstate (state, NULL);
+#else
+ vlc_control_cancel (VLC_RESTORE_CANCEL, state);
#endif
}
@@ -624,6 +638,8 @@ static inline void vlc_testcancel (void)
{
#if defined (LIBVLC_USE_PTHREAD)
pthread_testcancel ();
+#else
+ vlc_control_cancel (VLC_TEST_CANCEL);
#endif
}
diff --git a/src/libvlccore.sym b/src/libvlccore.sym
index f61c17d..78aaf52 100644
--- a/src/libvlccore.sym
+++ b/src/libvlccore.sym
@@ -426,6 +426,7 @@ __vlc_cond_destroy
__vlc_cond_init
vlc_config_create
vlc_config_set
+vlc_control_cancel
vlc_CPU
vlc_error
__vlc_event_attach
diff --git a/src/misc/threads.c b/src/misc/threads.c
index af65ddb..97f9f19 100644
--- a/src/misc/threads.c
+++ b/src/misc/threads.c
@@ -31,6 +31,7 @@
#include <vlc_common.h>
#include "libvlc.h"
+#include <stdarg.h>
#include <assert.h>
#ifdef HAVE_UNISTD_H
# include <unistd.h>
@@ -836,3 +837,45 @@ void vlc_thread_cancel (vlc_object_t *obj)
if (priv->b_thread)
vlc_cancel (priv->thread_id);
}
+
+void vlc_control_cancel (int cmd, ...)
+{
+#ifdef LIBVLC_USE_PTHREAD
+ (void) cmd;
+ abort();
+#else
+ static __thread struct vlc_cancel_t *stack = NULL;
+ static __thread bool killed = false, killable = true;
+ va_list ap;
+
+ va_start (ap, cmd);
+
+ switch (cmd)
+ {
+ case VLC_SAVE_CANCEL:
+ {
+ int *p_state = va_arg (ap, int *);
+ *p_state = killable;
+ killable = false;
+ break;
+ }
+
+ case VLC_RESTORE_CANCEL:
+ {
+ int state = va_arg (ap, int);
+ killable = state != 0;
+ break;
+ }
+
+ case VLC_TEST_CANCEL:
+ if (killable)
+#ifdef WIN32
+ _endthread ();
+#else
+# error Not implemented!
+#endif
+ break;
+ }
+ va_end (ap);
+#endif
+}
More information about the vlc-devel
mailing list