]> git.sesse.net Git - vlc/blobdiff - include/vlc_threads_funcs.h
Audio output.
[vlc] / include / vlc_threads_funcs.h
index 707a0b749b3f5c88d4ce52596cb22870708bff66..c3996b6e00baff055d2b1a613c242392e2fab63c 100644 (file)
@@ -3,7 +3,7 @@
  * This header provides a portable threads implementation.
  *****************************************************************************
  * Copyright (C) 1999, 2002 VideoLAN
- * $Id: vlc_threads_funcs.h,v 1.1 2002/08/29 23:53:22 massiot Exp $
+ * $Id: vlc_threads_funcs.h,v 1.11 2002/12/18 11:47:35 sam Exp $
  *
  * Authors: Jean-Marc Dressler <polux@via.ecp.fr>
  *          Samuel Hocevar <sam@via.ecp.fr>
@@ -14,7 +14,7 @@
  * it under the terms of the GNU General Public License as published by
  * the Free Software Foundation; either version 2 of the License, or
  * (at your option) any later version.
- * 
+ *
  * This program is distributed in the hope that it will be useful,
  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
@@ -35,9 +35,11 @@ VLC_EXPORT( int,  __vlc_mutex_destroy, ( char *, int, vlc_mutex_t * ) );
 VLC_EXPORT( int,  __vlc_cond_init,     ( vlc_object_t *, vlc_cond_t * ) );
 VLC_EXPORT( int,  __vlc_cond_destroy,  ( char *, int, vlc_cond_t * ) );
 VLC_EXPORT( int,  __vlc_thread_create, ( vlc_object_t *, char *, int, char *, void * ( * ) ( void * ), int, vlc_bool_t ) );
+VLC_EXPORT( int,  __vlc_thread_set_priority, ( vlc_object_t *, char *, int, int ) );
 VLC_EXPORT( void, __vlc_thread_ready,  ( vlc_object_t * ) );
 VLC_EXPORT( void, __vlc_thread_join,   ( vlc_object_t *, char *, int ) );
 
+
 /*****************************************************************************
  * vlc_threads_init: initialize threads system
  *****************************************************************************/
@@ -74,7 +76,11 @@ static inline int __vlc_mutex_lock( char * psz_file, int i_line,
     i_result = pth_mutex_acquire( &p_mutex->mutex, TRUE, NULL );
 
 #elif defined( ST_INIT_IN_ST_H )
-    i_result = st_mutex_lock( *p_mutex->mutex );
+    i_result = st_mutex_lock( p_mutex->mutex );
+
+#elif defined( UNDER_CE )
+    EnterCriticalSection( &p_mutex->csection );
+    return 0;
 
 #elif defined( WIN32 )
     if( p_mutex->mutex )
@@ -141,7 +147,11 @@ static inline int __vlc_mutex_unlock( char * psz_file, int i_line,
     i_result = pth_mutex_release( &p_mutex->mutex );
 
 #elif defined( ST_INIT_IN_ST_H )
-    i_result = st_mutex_unlock( *p_mutex->mutex );
+    i_result = st_mutex_unlock( p_mutex->mutex );
+
+#elif defined( UNDER_CE )
+    LeaveCriticalSection( &p_mutex->csection );
+    return 0;
 
 #elif defined( WIN32 )
     if( p_mutex->mutex )
@@ -222,7 +232,11 @@ static inline int __vlc_cond_signal( char * psz_file, int i_line,
     i_result = pth_cond_notify( &p_condvar->cond, FALSE );
 
 #elif defined( ST_INIT_IN_ST_H )
-    i_result = st_cond_signal( *p_condvar->cond );
+    i_result = st_cond_signal( p_condvar->cond );
+
+#elif defined( UNDER_CE )
+    PulseEvent( p_condvar->event );
+    return 0;
 
 #elif defined( WIN32 )
     /* Release one waiting thread if one is available. */
@@ -315,6 +329,7 @@ static inline int __vlc_cond_signal( char * psz_file, int i_line,
                 return 0;
             }
         }
+        i_result = 0;
     }
 #endif
 
@@ -352,9 +367,21 @@ static inline int __vlc_cond_broadcast( char * psz_file, int i_line,
     i_result = pth_cond_notify( &p_condvar->cond, FALSE );
 
 #elif defined( ST_INIT_IN_ST_H )
-    i_result = st_cond_broadcast( *p_condvar->cond );
+    i_result = st_cond_broadcast( p_condvar->cond );
+
+#elif defined( UNDER_CE )
+    int i;
+
+    /* Release all waiting threads. */
+    for( i = p_condvar->i_waiting_threads; i > 0; i-- )
+    {
+        PulseEvent( p_condvar->event );
+    }
+    return 0;
 
 #elif defined( WIN32 )
+    int i;
+
     /* Release all waiting threads. */
     if( !p_condvar->semaphore )
     {
@@ -448,6 +475,7 @@ static inline int __vlc_cond_broadcast( char * psz_file, int i_line,
                 return 0;
             }
         }
+        i_result = 0;
     }
 #endif
 
@@ -479,9 +507,20 @@ static inline int __vlc_cond_wait( char * psz_file, int i_line,
     i_result = pth_cond_await( &p_condvar->cond, &p_mutex->mutex, NULL );
 
 #elif defined( ST_INIT_IN_ST_H )
-    st_mutex_unlock( *p_mutex->mutex );
-    i_result = st_cond_wait( *p_condvar->cond );
-    st_mutex_lock( *p_mutex->mutex );
+    st_mutex_unlock( p_mutex->mutex );
+    i_result = st_cond_wait( p_condvar->cond );
+    st_mutex_lock( p_mutex->mutex );
+
+#elif defined( UNDER_CE )
+    p_condvar->i_waiting_threads++;
+    LeaveCriticalSection( &p_mutex->csection );
+    WaitForSingleObject( p_condvar->event, INFINITE );
+    p_condvar->i_waiting_threads--;
+
+    /* Reacquire the mutex before returning. */
+    vlc_mutex_lock( p_mutex );
+
+    return 0;
 
 #elif defined( WIN32 )
     if( !p_condvar->semaphore )
@@ -489,7 +528,7 @@ static inline int __vlc_cond_wait( char * psz_file, int i_line,
         /* Increase our wait count */
         p_condvar->i_waiting_threads++;
 
-        if( p_condvar->SignalObjectAndWait && p_mutex->mutex )
+        if( p_mutex->mutex )
         {
             /* It is only possible to atomically release the mutex and
              * initiate the waiting on WinNT/2K/XP. Win9x doesn't have
@@ -579,7 +618,7 @@ static inline int __vlc_cond_wait( char * psz_file, int i_line,
         {
             msg_Warn( p_condvar->p_this,
                       "thread %d: possible deadlock detected "
-                      "in cond_wait at %s:%d (%s)", pthread_self(),
+                      "in cond_wait at %s:%d (%s)", (int)pthread_self(),
                       psz_file, i_line, strerror(i_result) );
         }
         else break;
@@ -647,6 +686,12 @@ static inline int __vlc_cond_wait( char * psz_file, int i_line,
 #define vlc_thread_create( P_THIS, PSZ_NAME, FUNC, PRIORITY, WAIT )         \
     __vlc_thread_create( VLC_OBJECT(P_THIS), __FILE__, __LINE__, PSZ_NAME, (void * ( * ) ( void * ))FUNC, PRIORITY, WAIT )
 
+/*****************************************************************************
+ * vlc_thread_set_priority: set the priority of the calling thread
+ *****************************************************************************/
+#define vlc_thread_set_priority( P_THIS, PRIORITY )                         \
+    __vlc_thread_set_priority( VLC_OBJECT(P_THIS), __FILE__, __LINE__, PRIORITY )
+
 /*****************************************************************************
  * vlc_thread_ready: tell the parent thread we were successfully spawned
  *****************************************************************************/
@@ -657,4 +702,4 @@ static inline int __vlc_cond_wait( char * psz_file, int i_line,
  * vlc_thread_join: wait until a thread exits
  *****************************************************************************/
 #define vlc_thread_join( P_THIS )                                           \
-    __vlc_thread_join( VLC_OBJECT(P_THIS), __FILE__, __LINE__ ) 
+    __vlc_thread_join( VLC_OBJECT(P_THIS), __FILE__, __LINE__ )