Bug 768000 - Fix up the mutex handling in the prior patch a=bajaj
authorJames Willcox <jwillcox@mozilla.com>
Fri, 25 Jan 2013 11:13:40 -0500
changeset 127357 542331c0575200ed0db9657ebf4e8b32b99458b0
parent 127356 f47d6dfbcee0e66e7618a36f58959c97db8688d1
child 127358 8c1ae6ca956a638a064327f9ee967841f91ff423
push id2151
push userlsblakk@mozilla.com
push dateTue, 19 Feb 2013 18:06:57 +0000
treeherdermozilla-beta@4952e88741ec [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbajaj
bugs768000
milestone20.0a2
Bug 768000 - Fix up the mutex handling in the prior patch a=bajaj
dom/plugins/base/android/ANPAudio.cpp
--- a/dom/plugins/base/android/ANPAudio.cpp
+++ b/dom/plugins/base/android/ANPAudio.cpp
@@ -93,21 +93,23 @@ struct ANPAudioTrack {
   jclass at_class;
 
   unsigned int rate;
   unsigned int channels;
   unsigned int bufferSize;
   unsigned int isStopped;
   unsigned int keepGoing;
 
-  mozilla::Mutex* lock;
+  mozilla::Mutex lock;
 
   void* user;
   ANPAudioCallbackProc proc;
   ANPSampleFormat format;
+
+  ANPAudioTrack() : lock("ANPAudioTrack") { }
 };
 
 class AudioRunnable : public nsRunnable
 {
 public:
   NS_DECL_NSIRUNNABLE
 
   AudioRunnable(ANPAudioTrack* aAudioTrack) {
@@ -146,17 +148,17 @@ AudioRunnable::Run()
   buffer.bufferData = (void*) byte;
 
   while (true)
   {
     // reset the buffer size
     buffer.size = mTrack->bufferSize;
     
     {
-      mozilla::MutexAutoLock lock(*mTrack->lock);
+      mozilla::MutexAutoLock lock(mTrack->lock);
 
       if (!mTrack->keepGoing)
         break;
 
       // Get data from the plugin
       mTrack->proc(kMoreData_ANPAudioEvent, mTrack->user, &buffer);
     }
 
@@ -183,33 +185,31 @@ AudioRunnable::Run()
     } while(wroteSoFar < buffer.size);
   }
 
   jenv->CallVoidMethod(mTrack->output_unit, at.release);
 
   jenv->DeleteGlobalRef(mTrack->output_unit);
   jenv->DeleteGlobalRef(mTrack->at_class);
 
-  delete mTrack->lock;
-
-  free(mTrack);
-
+  delete mTrack;
+  
   jenv->ReleaseByteArrayElements(bytearray, byte, 0);
 
   return NS_OK;
 }
 
 ANPAudioTrack*
 anp_audio_newTrack(uint32_t sampleRate,    // sampling rate in Hz
                    ANPSampleFormat format,
                    int channelCount,       // MONO=1, STEREO=2
                    ANPAudioCallbackProc proc,
                    void* user)
 {
-  ANPAudioTrack *s = (ANPAudioTrack*) malloc(sizeof(ANPAudioTrack));
+  ANPAudioTrack *s = new ANPAudioTrack();
   if (s == NULL) {
     return NULL;
   }
 
   JNIEnv *jenv = GetJNIForThread();
   if (!jenv)
     return NULL;
 
@@ -217,17 +217,16 @@ anp_audio_newTrack(uint32_t sampleRate, 
   s->rate = sampleRate;
   s->channels = channelCount;
   s->bufferSize = s->rate * s->channels;
   s->isStopped = true;
   s->keepGoing = false;
   s->user = user;
   s->proc = proc;
   s->format = format;
-  s->lock = new mozilla::Mutex("ANPAudioTrack");
 
   int jformat;
   switch (format) {
   case kPCM16Bit_ANPSampleFormat:
     jformat = ENCODING_PCM_16BIT;
     break;
   case kPCM8Bit_ANPSampleFormat:
     jformat = ENCODING_PCM_8BIT;
@@ -283,17 +282,17 @@ anp_audio_newTrack(uint32_t sampleRate, 
 
 void
 anp_audio_deleteTrack(ANPAudioTrack* s)
 {
   if (s == NULL) {
     return;
   }
 
-  mozilla::MutexAutoLock lock(*s->lock);
+  mozilla::MutexAutoLock lock(s->lock);
   s->keepGoing = false;
 
   // deallocation happens in the AudioThread.  There is a
   // potential leak if anp_audio_start is never called, but
   // we do not see that from flash.
 }
 
 void