]> git.sesse.net Git - vlc/commitdiff
vlc_savecancel, vlc_restorecancel: POSIX cancellation state management
authorRémi Denis-Courmont <rdenis@simphalempin.com>
Sun, 6 Jul 2008 17:55:17 +0000 (20:55 +0300)
committerRémi Denis-Courmont <rdenis@simphalempin.com>
Wed, 27 Aug 2008 19:43:02 +0000 (22:43 +0300)
include/vlc_threads.h

index 748f15edb0042bba2644d5f40d81a0070251b3a9..6ce24237ae4569f285ee57a0ef4659caea14b5fc 100644 (file)
@@ -3,7 +3,7 @@
  * This header provides portable declarations for mutexes & conditions
  *****************************************************************************
  * Copyright (C) 1999, 2002 the VideoLAN team
- * $Id$
+ * Copyright © 2007-2008 Rémi Denis-Courmont
  *
  * Authors: Jean-Marc Dressler <polux@via.ecp.fr>
  *          Samuel Hocevar <sam@via.ecp.fr>
@@ -588,6 +588,32 @@ static inline void barrier (void)
 #endif
 }
 
+/**
+ * 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
+ * cancellation-safe.
+ * @param p_state storage for the previous cancellation state
+ * @return Nothing, always succeeds.
+ */
+static inline void vlc_savecancel (int *p_state)
+{
+#if defined (LIBVLC_USE_PTHREAD)
+    (void) pthread_setcancelstate (PTHREAD_CANCEL_DISABLE, p_state);
+#endif
+}
+
+/**
+ * Restore the cancellation state for the calling thread.
+ * @param state previous state as returned by vlc_savecancel().
+ * @return Nothing, always succeeds.
+ */
+static inline void vlc_restorecancel (int state)
+{
+#if defined (LIBVLC_USE_PTHREAD)
+    (void) pthread_setcancelstate (state, NULL);
+#endif
+}
+
 /*****************************************************************************
  * vlc_thread_create: create a thread
  *****************************************************************************/