]> git.sesse.net Git - vlc/blobdiff - src/misc/threads.c
vlc_cond_init: really remove useless parameter
[vlc] / src / misc / threads.c
index 7d62c3f543ad46ce339633fbaf26c67980411297..73fd49ab552bd5ee28f371d965d4e89885e71a29 100644 (file)
@@ -52,6 +52,8 @@ static volatile unsigned i_initializations = 0;
 # include <sched.h>
 
 static pthread_mutex_t once_mutex = PTHREAD_MUTEX_INITIALIZER;
+#else
+static vlc_threadvar_t cancel_key;
 #endif
 
 /**
@@ -66,28 +68,54 @@ libvlc_global_data_t *vlc_global( void )
     return p_root;
 }
 
-#if defined(LIBVLC_USE_PTHREAD)
+#ifdef HAVE_EXECINFO_H
+# include <execinfo.h>
+#endif
+
+/**
+ * Print a backtrace to the standard error for debugging purpose.
+ */
+void vlc_trace (const char *fn, const char *file, unsigned line)
+{
+     fprintf (stderr, "at %s:%u in %s\n", file, line, fn);
+     fflush (stderr); /* needed before switch to low-level I/O */
+#ifdef HAVE_BACKTRACE
+     void *stack[20];
+     int len = backtrace (stack, sizeof (stack) / sizeof (stack[0]));
+     backtrace_symbols_fd (stack, len, 2);
+#endif
+#ifndef WIN32
+     fsync (2);
+#endif
+}
+
 static inline unsigned long vlc_threadid (void)
 {
+#if defined(LIBVLC_USE_PTHREAD)
      union { pthread_t th; unsigned long int i; } v = { };
      v.th = pthread_self ();
      return v.i;
-}
 
-#if defined(HAVE_EXECINFO_H) && defined(HAVE_BACKTRACE)
-# include <execinfo.h>
+#elif defined (WIN32)
+     return GetCurrentThreadId ();
+
+#else
+     return 0;
+
 #endif
+}
 
 /*****************************************************************************
  * vlc_thread_fatal: Report an error from the threading layer
  *****************************************************************************
  * This is mostly meant for debugging.
  *****************************************************************************/
-void vlc_pthread_fatal (const char *action, int error,
+void vlc_thread_fatal (const char *action, int error, const char *function,
                         const char *file, unsigned line)
 {
-    fprintf (stderr, "LibVLC fatal error %s in thread %lu at %s:%u: %d\n",
-             action, vlc_threadid (), file, line, error);
+    fprintf (stderr, "LibVLC fatal error %s (%d) in thread %lu ",
+             action, error, vlc_threadid ());
+    vlc_trace (function, file, line);
 
     /* Sometimes strerror_r() crashes too, so make sure we print an error
      * message before we invoke it */
@@ -95,7 +123,7 @@ void vlc_pthread_fatal (const char *action, int error,
     /* Avoid the strerror_r() prototype brain damage in glibc */
     errno = error;
     fprintf (stderr, " Error message: %m at:\n");
-#else
+#elif !defined (WIN32)
     char buf[1000];
     const char *msg;
 
@@ -115,24 +143,8 @@ void vlc_pthread_fatal (const char *action, int error,
 #endif
     fflush (stderr);
 
-#ifdef HAVE_BACKTRACE
-    void *stack[20];
-    int len = backtrace (stack, sizeof (stack) / sizeof (stack[0]));
-    backtrace_symbols_fd (stack, len, 2);
-#endif
-
     abort ();
 }
-#else
-void vlc_pthread_fatal (const char *action, int error,
-                        const char *file, unsigned line)
-{
-    (void)action; (void)error; (void)file; (void)line;
-    abort();
-}
-
-static vlc_threadvar_t cancel_key;
-#endif
 
 /**
  * Per-thread cancellation data
@@ -254,27 +266,6 @@ int vlc_mutex_init( vlc_mutex_t *p_mutex )
     *p_mutex = CreateMutex( 0, FALSE, 0 );
     return (*p_mutex != NULL) ? 0 : ENOMEM;
 
-#elif defined( HAVE_KERNEL_SCHEDULER_H )
-    /* check the arguments and whether it's already been initialized */
-    if( p_mutex == NULL )
-    {
-        return B_BAD_VALUE;
-    }
-
-    if( p_mutex->init == 9999 )
-    {
-        return EALREADY;
-    }
-
-    p_mutex->lock = create_sem( 1, "BeMutex" );
-    if( p_mutex->lock < B_NO_ERROR )
-    {
-        return( -1 );
-    }
-
-    p_mutex->init = 9999;
-    return B_OK;
-
 #endif
 }
 
@@ -325,19 +316,13 @@ void __vlc_mutex_destroy( const char * psz_file, int i_line, vlc_mutex_t *p_mute
 
     CloseHandle( *p_mutex );
 
-#elif defined( HAVE_KERNEL_SCHEDULER_H )
-    if( p_mutex->init == 9999 )
-        delete_sem( p_mutex->lock );
-
-    p_mutex->init = 0;
-
 #endif
 }
 
 /*****************************************************************************
- * vlc_cond_init: initialize a condition
+ * vlc_cond_init: initialize a condition variable
  *****************************************************************************/
-int __vlc_cond_init( vlc_cond_t *p_condvar )
+int vlc_cond_init( vlc_cond_t *p_condvar )
 {
 #if defined( LIBVLC_USE_PTHREAD )
     pthread_condattr_t attr;
@@ -368,21 +353,6 @@ int __vlc_cond_init( vlc_cond_t *p_condvar )
                               NULL ); /* unnamed */
     return *p_condvar ? 0 : ENOMEM;
 
-#elif defined( HAVE_KERNEL_SCHEDULER_H )
-    if( !p_condvar )
-    {
-        return B_BAD_VALUE;
-    }
-
-    if( p_condvar->init == 9999 )
-    {
-        return EALREADY;
-    }
-
-    p_condvar->thread = -1;
-    p_condvar->init = 9999;
-    return 0;
-
 #endif
 }
 
@@ -400,9 +370,6 @@ void __vlc_cond_destroy( const char * psz_file, int i_line, vlc_cond_t *p_condva
 
     CloseHandle( *p_condvar );
 
-#elif defined( HAVE_KERNEL_SCHEDULER_H )
-    p_condvar->init = 0;
-
 #endif
 }
 
@@ -555,10 +522,6 @@ int vlc_clone (vlc_thread_t *p_handle, void * (*entry) (void *), void *data,
         free (th);
     }
 
-#elif defined( HAVE_KERNEL_SCHEDULER_H )
-    *p_handle = spawn_thread( entry, psz_name, priority, data );
-    ret = resume_thread( *p_handle );
-
 #endif
     return ret;
 }
@@ -604,7 +567,7 @@ void vlc_join (vlc_thread_t handle, void **result)
 #if defined( LIBVLC_USE_PTHREAD )
     int val = pthread_join (handle, result);
     if (val)
-        vlc_pthread_fatal ("joining thread", val, __FILE__, __LINE__);
+        vlc_thread_fatal ("joining thread", val, __func__, __FILE__, __LINE__);
 
 #elif defined( UNDER_CE ) || defined( WIN32 )
     do
@@ -617,12 +580,6 @@ void vlc_join (vlc_thread_t handle, void **result)
         *result = handle->data;
     free (handle);
 
-#elif defined( HAVE_KERNEL_SCHEDULER_H )
-    int32_t exit_value;
-    int val = (B_OK == wait_for_thread( p_priv->thread_id, &exit_value ));
-    if( !val && result )
-        *result = (void *)exit_value;
-
 #endif
 }
 
@@ -847,8 +804,6 @@ void vlc_control_cancel (int cmd, ...)
 #else
     va_list ap;
 
-    va_start (ap, cmd);
-
     vlc_cancel_t *nfo = vlc_threadvar_get (&cancel_key);
     if (nfo == NULL)
     {
@@ -864,6 +819,7 @@ void vlc_control_cancel (int cmd, ...)
 #endif
     }
 
+    va_start (ap, cmd);
     switch (cmd)
     {
         case VLC_SAVE_CANCEL: