]> git.sesse.net Git - vlc/blobdiff - modules/video_filter/atmo/AtmoThread.cpp
android: Enable the iomx module
[vlc] / modules / video_filter / atmo / AtmoThread.cpp
index ad082172f8a2a9c6e273bd444e7d1c0852b5d387..50c9c4b574cf3409b74b6f3b777df23d3fbade7a 100644 (file)
@@ -5,37 +5,35 @@
  *
  * $Id$
  */
+
+#ifdef HAVE_CONFIG_H
+# include "config.h"
+#endif
+#include <assert.h>
+
 #include "AtmoThread.h"
 
 #if defined(_ATMO_VLC_PLUGIN_)
 
 CThread::CThread(vlc_object_t *pOwner)
 {
-    int err;
-    m_pAtmoThread = (atmo_thread_t *)vlc_object_create( pOwner,
-                                                        sizeof(atmo_thread_t) );
-    if(m_pAtmoThread)
-    {
-        m_pAtmoThread->p_thread = this;
-        this->m_pOwner = pOwner;
-
-        vlc_object_attach( m_pAtmoThread, m_pOwner);
-
-        vlc_mutex_init( m_pAtmoThread, &m_TerminateLock );
-        err = vlc_cond_init( m_pAtmoThread, &m_TerminateCond );
-        if(err) {
-           msg_Err( m_pAtmoThread, "vlc_cond_init failed %d",err);
-        }
-    }
+    m_bTerminated  = ATMO_FALSE;
+    vlc_mutex_init( &m_TerminateLock );
+    vlc_cond_init( &m_TerminateCond );
+    m_pOwner = pOwner;
+    m_HasThread = ATMO_FALSE;
 }
 
 #else
 
 CThread::CThread(void)
 {
+  m_bTerminated  = ATMO_FALSE;
+
   m_hThread = CreateThread(NULL, 0, CThread::ThreadProc ,
                            this, CREATE_SUSPENDED, &m_dwThreadID);
-  m_hTerminateEvent = CreateEvent(NULL,ATMO_FALSE,ATMO_FALSE,NULL);
+
+  m_hTerminateEvent = CreateEvent(NULL,0,0,NULL);
 }
 
 #endif
@@ -46,13 +44,9 @@ CThread::CThread(void)
 
 CThread::~CThread(void)
 {
-  if(m_pAtmoThread)
-  {
-      vlc_mutex_destroy( &m_TerminateLock );
-      vlc_cond_destroy( &m_TerminateCond );
-      vlc_object_detach(m_pAtmoThread);
-      vlc_object_release(m_pAtmoThread);
-  }
+  assert(m_HasThread == ATMO_FALSE);
+  vlc_mutex_destroy( &m_TerminateLock );
+  vlc_cond_destroy( &m_TerminateCond );
 }
 
 #else
@@ -67,25 +61,24 @@ CThread::~CThread(void)
 
 #if defined(_ATMO_VLC_PLUGIN_)
 
-void CThread::ThreadProc(atmo_thread_t *pAtmoThread)
+void *CThread::ThreadProc(void *obj)
 {
-      CThread *pThread = (CThread *)pAtmoThread->p_thread;
-      if(pThread) {
-         // give feedback I'am running?
-         vlc_thread_ready( pThread->m_pAtmoThread );
+      CThread *pThread = static_cast<CThread*>(obj);
 
-            pThread->Execute();
+      int canc = vlc_savecancel ();
+      pThread->Execute();
+      vlc_restorecancel (canc);
 
-      }
+      return NULL;
 }
 
 #else
 
 DWORD WINAPI CThread::ThreadProc(LPVOID lpParameter)
 {
-          CThread *aThread = (CThread *)lpParameter;
-          if(aThread)
-             return aThread->Execute();
+          CThread *pThread = (CThread *)lpParameter;
+          if(pThread)
+             return pThread->Execute();
           else
                  return (DWORD)-1;
 }
@@ -109,19 +102,20 @@ void CThread::Terminate(void)
 {
    // Set Termination Flag and EventObject!
    // and wait for Termination
-   m_bTerminated = ATMO_TRUE;
 
 #if defined(_ATMO_VLC_PLUGIN_)
-   if(m_pAtmoThread)
+   if(m_HasThread != ATMO_FALSE)
    {
       vlc_mutex_lock( &m_TerminateLock );
+      m_bTerminated = ATMO_TRUE;
       vlc_cond_signal( &m_TerminateCond  );
       vlc_mutex_unlock( &m_TerminateLock );
-      vlc_object_kill( m_pAtmoThread );
 
-      vlc_thread_join( m_pAtmoThread );
+      vlc_cancel( m_Thread );
+      vlc_join( m_Thread, NULL );
    }
 #else
+   m_bTerminated = ATMO_TRUE;
    SetEvent(m_hTerminateEvent);
    WaitForSingleObject(m_hThread,INFINITE);
 #endif
@@ -132,14 +126,14 @@ void CThread::Run()
    m_bTerminated = ATMO_FALSE;
 
 #if defined(_ATMO_VLC_PLUGIN_)
-   m_pAtmoThread->b_die = false;
-   if(vlc_thread_create( m_pAtmoThread,
-                         "Atmo-CThread-Class",
-                         CThread::ThreadProc,
-                         VLC_THREAD_PRIORITY_LOW,
-                         false ))
+   if (vlc_clone( &m_Thread, CThread::ThreadProc, this, VLC_THREAD_PRIORITY_LOW))
+   {
+       m_HasThread = ATMO_FALSE;
+       msg_Err( m_pOwner, "cannot launch one of the AtmoLight threads");
+   }
+   else
    {
-      msg_Err( m_pOwner, "cannot launch one of the AtmoLight threads");
+       m_HasThread = ATMO_TRUE;;
    }
 
 #else
@@ -157,12 +151,14 @@ void CThread::Run()
 ATMO_BOOL CThread::ThreadSleep(DWORD millisekunden)
 {
 #if defined(_ATMO_VLC_PLUGIN_)
+     ATMO_BOOL temp;
      vlc_mutex_lock( &m_TerminateLock );
-     int value = vlc_cond_timedwait(&m_TerminateCond,
-                                    &m_TerminateLock,
-                                    mdate() + (mtime_t)(millisekunden * 1000));
+     vlc_cond_timedwait(&m_TerminateCond,
+                        &m_TerminateLock,
+                        mdate() + (mtime_t)(millisekunden * 1000));
+     temp = m_bTerminated;
      vlc_mutex_unlock( &m_TerminateLock );
-     return (value != 0);
+     return !temp;
 
 #else
      DWORD res = WaitForSingleObject(m_hTerminateEvent,millisekunden);