-/*****************************************************************************
- * vlc_cond_wait: wait until condition completion
- *****************************************************************************/
-#define vlc_cond_wait( P_COND, P_MUTEX ) \
- __vlc_cond_wait( __FILE__, __LINE__, P_COND, P_MUTEX )
-
-static inline void __vlc_cond_wait( const char * psz_file, int i_line,
- vlc_cond_t *p_condvar, vlc_mutex_t *p_mutex )
-{
-#if defined(LIBVLC_USE_PTHREAD)
- int val = pthread_cond_wait( p_condvar, p_mutex );
- VLC_THREAD_ASSERT ("waiting on condition");
-
-#elif defined( UNDER_CE )
- LeaveCriticalSection( &p_mutex->csection );
- WaitForSingleObject( *p_condvar, INFINITE );
-
- /* Reacquire the mutex before returning. */
- vlc_mutex_lock( p_mutex );
-
-#elif defined( WIN32 )
- (void)psz_file; (void)i_line;
-
- /* Increase our wait count */
- SignalObjectAndWait( *p_mutex, *p_condvar, INFINITE, FALSE );
-
- /* Reacquire the mutex before returning. */
- vlc_mutex_lock( p_mutex );
-
-#elif defined( SYS_BEOS )
- /* The p_condvar->thread var is initialized before the unlock because
- * it enables to identify when the thread is interrupted beetwen the
- * unlock line and the suspend_thread line */
- p_condvar->thread = find_thread( NULL );
- vlc_mutex_unlock( p_mutex );
- suspend_thread( p_condvar->thread );
- p_condvar->thread = -1;
-
- vlc_mutex_lock( p_mutex );
-
-#endif
-}
+#if defined (LIBVLC_USE_PTHREAD_CANCEL)
+/**
+ * Registers a new procedure to run if the thread is cancelled (or otherwise
+ * exits prematurely). Any call to vlc_cleanup_push() <b>must</b> paired with a
+ * call to either vlc_cleanup_pop() or vlc_cleanup_run(). Branching into or out
+ * of the block between these two function calls is not allowed (read: it will
+ * likely crash the whole process). If multiple procedures are registered,
+ * they are handled in last-in first-out order.
+ *
+ * @param routine procedure to call if the thread ends
+ * @param arg argument for the procedure
+ */
+# define vlc_cleanup_push( routine, arg ) pthread_cleanup_push (routine, arg)