Author: rolf
Date: 2008-01-25 03:15:37 -0500 (Fri, 25 Jan 2008)
New Revision: 93874

Modified:
   trunk/moon/src/ChangeLog
   trunk/moon/src/pipeline.cpp
   trunk/moon/src/pipeline.h
Log:
* pipeline.cpp, pipeline.h: Media: Don't create the worker thread upon
  first usage, but on construction, and finish it upon destruction.
  Fixes race between creating and destructing the thread.

Modified: trunk/moon/src/ChangeLog
===================================================================
--- trunk/moon/src/ChangeLog    2008-01-25 03:47:12 UTC (rev 93873)
+++ trunk/moon/src/ChangeLog    2008-01-25 08:15:37 UTC (rev 93874)
@@ -1,3 +1,9 @@
+2008-01-25  Rolf Bjarne Kvinge <[EMAIL PROTECTED]> 
+
+       * pipeline.cpp, pipeline.h: Media: Don't create the worker thread upon 
first
+         usage, but on construction, and finish it upon destruction. Fixes race
+         between creating and destructing the thread.
+
 2008-01-24  Chris Toshok  <[EMAIL PROTECTED]>
 
        * stylus.cpp (Stroke::HitTestEndcapSegment): implement.

Modified: trunk/moon/src/pipeline.cpp
===================================================================
--- trunk/moon/src/pipeline.cpp 2008-01-25 03:47:12 UTC (rev 93873)
+++ trunk/moon/src/pipeline.cpp 2008-01-25 08:15:37 UTC (rev 93874)
@@ -58,12 +58,38 @@
                demuxer (NULL), markers (NULL),
                start_time (0), opened (false)
 {
+       pthread_attr_t attribs;
+       queued_requests = new List ();
+       
+       pthread_attr_init (&attribs);
+       pthread_attr_setdetachstate (&attribs, PTHREAD_CREATE_JOINABLE);
+       
+       pthread_mutex_init (&queue_mutex, NULL);
+       pthread_cond_init (&queue_condition, NULL);
+       
+       pthread_create (&queue_thread, &attribs, WorkerLoop, this);     
+       pthread_attr_destroy (&attribs);
 }
 
 Media::~Media ()
 {
-       DeleteQueue ();
+       pthread_mutex_lock (&queue_mutex);
+       queued_requests->Clear (true);
+       delete queued_requests;
+       queued_requests = NULL;
+       pthread_cond_signal (&queue_condition);
+       pthread_mutex_unlock (&queue_mutex);
        
+       if (source->GetType () == MediaSourceTypeProgressive) {
+               ProgressiveSource *ps = (ProgressiveSource *) source;
+               ps->CancelWait ();
+       }
+       
+       pthread_join (queue_thread, NULL);
+       pthread_mutex_destroy (&queue_mutex);
+       pthread_cond_destroy (&queue_condition);
+       pthread_detach (queue_thread);
+               
        delete source;
        delete demuxer;
        g_free (file_or_url);
@@ -574,23 +600,9 @@
 void
 Media::EnqueueWork (MediaWork *work)
 {
-       pthread_attr_t attribs;
        MediaWork *current;
        
        //printf ("Media::EnqueueWork (%p).\n", stream);
-       if (queued_requests == NULL) {
-               //printf ("Media::EnqueueWork (%p). Creating threads.\n", 
stream);
-               queued_requests = new List ();
-               
-               pthread_attr_init (&attribs);
-               pthread_attr_setdetachstate (&attribs, PTHREAD_CREATE_JOINABLE);
-               
-               pthread_mutex_init (&queue_mutex, NULL);
-               pthread_cond_init (&queue_condition, NULL);
-               
-               pthread_create (&queue_thread, &attribs, WorkerLoop, this);     
-               pthread_attr_destroy (&attribs);                
-       }
        
        pthread_mutex_lock (&queue_mutex);
        
@@ -644,36 +656,6 @@
        }
 }
 
-void
-Media::DeleteQueue ()
-{
-       //printf ("Media::DeleteQueue ().\n");
-       if (queued_requests != NULL) {
-               pthread_mutex_lock (&queue_mutex);
-               queued_requests->Clear (true);
-               delete queued_requests;
-               queued_requests = NULL;
-               pthread_cond_signal (&queue_condition);
-               pthread_mutex_unlock (&queue_mutex);
-               
-               if (source->GetType () == MediaSourceTypeProgressive) {
-                       ProgressiveSource *ps = (ProgressiveSource *) source;
-                       ps->CancelWait ();
-               }
-               
-               pthread_join (queue_thread, NULL);
-               pthread_mutex_destroy (&queue_mutex);
-               pthread_cond_destroy (&queue_condition);
-               pthread_detach (queue_thread);
-       }
-       
-       if (source != NULL && source->GetType () == MediaSourceTypeProgressive) 
{
-               ProgressiveSource *ps = (ProgressiveSource *) source;
-               ps->CancelWait ();
-       }
-}
-
-
 /*
  * ASFDemuxer
  */

Modified: trunk/moon/src/pipeline.h
===================================================================
--- trunk/moon/src/pipeline.h   2008-01-25 03:47:12 UTC (rev 93873)
+++ trunk/moon/src/pipeline.h   2008-01-25 08:15:37 UTC (rev 93874)
@@ -18,7 +18,6 @@
 #include <pthread.h>
 
 #include "debug.h"
-#include "value.h"
 
 /*
  *     Should be capable of:
@@ -302,7 +301,6 @@
        void GetNextFrameAsync (MediaFrame *frame); 
        void GetNextFrameAsync (MediaFrame *frame, uint16_t states); 
        void ClearQueue (); // Clears the queue and make sure the thread has 
finished processing what it's doing
-       void DeleteQueue (); // Deletes the queue and finishes the thread 
that's processing the queue.
        void SetQueueCallback (MediaClosure *closure) { queue_closure = 
closure; }
        
        IMediaSource *GetSource () { return source; }

_______________________________________________
Mono-patches maillist  -  [email protected]
http://lists.ximian.com/mailman/listinfo/mono-patches

Reply via email to