]> git.sesse.net Git - vlc/blobdiff - include/vlc_threads.h
Optimized a bit bs_skip.
[vlc] / include / vlc_threads.h
index 4050150378b29c07f593f419f05584cbeee091f4..0232dc78df8be09163085436dddbbeb98fedd6a8 100644 (file)
 #if defined (LIBVLC_USE_PTHREAD)
 typedef pthread_t       vlc_thread_t;
 typedef pthread_mutex_t vlc_mutex_t;
+#define VLC_STATIC_MUTEX PTHREAD_MUTEX_INITIALIZER
 typedef pthread_cond_t  vlc_cond_t;
 typedef pthread_key_t   vlc_threadvar_t;
 
@@ -114,16 +115,18 @@ typedef struct
     HANDLE handle;
     void  *(*entry) (void *);
     void  *data;
+#if defined( UNDER_CE )
+    HANDLE cancel_event;
+#endif
 } *vlc_thread_t;
 
 typedef struct
 {
     CRITICAL_SECTION mutex;
-    LONG             owner;
-    unsigned         recursion;
-    bool             recursive;
-}
-vlc_mutex_t;
+    LONG initialized;
+} vlc_mutex_t;
+#define VLC_STATIC_MUTEX { .initialized = 0, }
+
 typedef HANDLE  vlc_cond_t;
 typedef DWORD   vlc_threadvar_t;
 
@@ -169,7 +172,8 @@ enum {
 };
 #endif
 
-#define vlc_thread_ready vlc_object_signal
+VLC_EXPORT(void, vlc_thread_ready, (vlc_object_t *obj));
+#define vlc_thread_ready(o) vlc_thread_ready(VLC_OBJECT(o))
 
 /**
  * Save the cancellation state and disable cancellation for the calling thread.
@@ -356,7 +360,12 @@ typedef CRITICAL_SECTION vlc_spinlock_t;
  */
 static inline int vlc_spin_init (vlc_spinlock_t *spin)
 {
+#ifdef UNDER_CE
+    InitializeCriticalSection(spin);
+    return 0;
+#else
     return !InitializeCriticalSectionAndSpinCount(spin, 4000);
+#endif
 }
 
 /**
@@ -442,4 +451,27 @@ static inline void barrier (void)
 #define vlc_thread_join( P_THIS )                                           \
     __vlc_thread_join( VLC_OBJECT(P_THIS) )
 
+#ifdef __cplusplus
+/**
+ * Helper C++ class to lock a mutex.
+ * The mutex is locked when the object is created, and unlocked when the object
+ * is destroyed.
+ */
+class vlc_mutex_locker
+{
+    private:
+        vlc_mutex_t *lock;
+    public:
+        vlc_mutex_locker (vlc_mutex_t *m) : lock (m)
+        {
+            vlc_mutex_lock (lock);
+        }
+
+        ~vlc_mutex_locker (void)
+        {
+            vlc_mutex_unlock (lock);
+        }
+};
+#endif
+
 #endif /* !_VLC_THREADS_H */