]> git.sesse.net Git - vlc/blobdiff - include/threads.h
* Disabled network input under BeOS so that it compiles again. We'll
[vlc] / include / threads.h
index 7d195508dc6f477355f0b6d85bcf2e6b4387cb42..a36c95c08dd889586dc0dbc441a037d298852e59 100644 (file)
@@ -152,7 +152,10 @@ static __inline__ int vlc_thread_create( vlc_thread_t *p_thread,
                                          char *psz_name, vlc_thread_func_t func,
                                          void *p_data)
 {
-#if defined(HAVE_CTHREADS_H)
+#if defined(HAVE_PTHREAD_H)
+    return pthread_create( p_thread, NULL, func, p_data );
+
+#elif defined(HAVE_CTHREADS_H)
     *p_thread = cthread_fork( (cthread_fn_t)func, (any_t)p_data );
     return 0;
 
@@ -161,9 +164,6 @@ static __inline__ int vlc_thread_create( vlc_thread_t *p_thread,
                               B_NORMAL_PRIORITY, p_data );
     return resume_thread( *p_thread );
 
-#elif defined(HAVE_PTHREAD_H)
-    return pthread_create( p_thread, NULL, func, p_data );
-
 #endif
 }
 
@@ -281,12 +281,17 @@ static __inline__ int vlc_mutex_unlock( vlc_mutex_t *p_mutex )
 }
 
 /*****************************************************************************
- * vlc_mutex_destroy: destory a mutex
+ * vlc_mutex_destroy: destroy a mutex
  *****************************************************************************/
 static __inline__ int vlc_mutex_destroy( vlc_mutex_t *p_mutex )
 {
 #if defined(HAVE_PTHREAD_H)    
     return pthread_mutex_destroy( p_mutex );
+#elif defined(HAVE_KERNEL_SCHEDULER_H) && defined(HAVE_KERNEL_OS_H)
+    if( p_mutex->init == 9999 )
+        delete_sem( p_mutex->lock );
+    p_mutex->init = 0;
+    return B_OK;
 #endif    
 }
 
@@ -343,27 +348,27 @@ static __inline__ int vlc_cond_signal( vlc_cond_t *p_condvar )
 
     if( p_condvar->init < 2000 )
         return B_NO_INIT;
-
     while( p_condvar->thread != -1 )
     {
         thread_info info;
         if( get_thread_info(p_condvar->thread, &info) == B_BAD_VALUE )
             return 0;
 
-        // is the thread sleeping ?
         if( info.state != B_THREAD_SUSPENDED )
         {
-            // wait a little
+            // The  waiting thread is not suspended so it could
+            // have been interrupted beetwen the unlock and the
+            // suspend_thread line. That is why we sleep a little
+            // before retesting p_condver->thread.
             snooze( 10000 );
         }
         else
         {
-            // ok, we have to wake up that thread
+            // Ok, we have to wake up that thread
             resume_thread( p_condvar->thread );
             return 0;
         }
     }
-    
     return 0;
 
 #endif
@@ -391,6 +396,9 @@ static __inline__ int vlc_cond_wait( vlc_cond_t *p_condvar, vlc_mutex_t *p_mutex
     if( p_condvar->init < 2000 )
         return B_NO_INIT;
 
+    // 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 );
@@ -403,11 +411,14 @@ static __inline__ int vlc_cond_wait( vlc_cond_t *p_condvar, vlc_mutex_t *p_mutex
 }
 
 /*****************************************************************************
- * vlc_cond_destory: destroy a condition
+ * vlc_cond_destroy: destroy a condition
  *****************************************************************************/
 static __inline__ int vlc_cond_destroy( vlc_cond_t *p_condvar )
 {
 #if defined(HAVE_PTHREAD_H)
     return pthread_cond_destroy( p_condvar );
+#elif defined(HAVE_KERNEL_SCHEDULER_H) && defined(HAVE_KERNEL_OS_H)
+    p_condvar->init = 0;
+    return 0;
 #endif    
 }