# include <sched.h>
static pthread_mutex_t once_mutex = PTHREAD_MUTEX_INITIALIZER;
+#else
+static vlc_threadvar_t cancel_key;
#endif
/**
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 */
/* 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;
#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
*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
}
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;
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
}
CloseHandle( *p_condvar );
-#elif defined( HAVE_KERNEL_SCHEDULER_H )
- p_condvar->init = 0;
-
#endif
}
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;
}
#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
*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
}
#else
va_list ap;
- va_start (ap, cmd);
-
vlc_cancel_t *nfo = vlc_threadvar_get (&cancel_key);
if (nfo == NULL)
{
#endif
}
+ va_start (ap, cmd);
switch (cmd)
{
case VLC_SAVE_CANCEL: