Advertisement
jeanleflambeur

deadlock.patch

Jan 6th, 2015
393
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Diff 3.63 KB | None | 0 0
  1. diff -ur private/private_impl.cpp private_new/private_impl.cpp
  2. --- private/private_impl.cpp    2014-04-03 18:19:38.000000000 +0200
  3. +++ private_new/private_impl.cpp    2015-01-07 00:05:24.938809432 +0100
  4. @@ -468,7 +468,7 @@
  5.              PORT_USERDATA *pData = ( PORT_USERDATA * ) port->userdata;
  6.  
  7.              bool hasGrabbed=false;
  8. -            pData->_mutex.lock();
  9. +            std::unique_lock<std::mutex> lck ( pData->_mutex );
  10.              if ( pData ) {
  11.                  if ( pData->wantToGrab &&  buffer->length ) {
  12.                      mmal_buffer_header_mem_lock ( buffer );
  13. @@ -479,8 +479,6 @@
  14.                      mmal_buffer_header_mem_unlock ( buffer );
  15.                  }
  16.              }
  17. -            pData->_mutex.unlock();
  18. -            if ( hasGrabbed ) pData->Thcond.BroadCast(); //wake up waiting client
  19.              // release buffer back to the pool
  20.              mmal_buffer_header_release ( buffer );
  21.              // and send one back to the port (if still open)
  22. @@ -499,6 +497,8 @@
  23.              if ( pData->pstate->shutterSpeed!=0 )
  24.                  mmal_port_parameter_set_uint32 ( pData->pstate->camera_component->control, MMAL_PARAMETER_SHUTTER_SPEED, pData->pstate->shutterSpeed ) ;
  25.  
  26. +            //pData->_mutex.unlock(); //no need to do this anymore - the Broadcast  will unlock the mutex as well
  27. +            if ( hasGrabbed ) pData->Thcond.BroadCast(); //wake up waiting client
  28.          }
  29.  
  30.  
  31. diff -ur private/private_impl.h private_new/private_impl.h
  32. --- private/private_impl.h  2014-04-03 18:19:38.000000000 +0200
  33. +++ private_new/private_impl.h  2015-01-07 00:05:44.382808840 +0100
  34. @@ -61,10 +61,9 @@
  35.                      pstate=0;
  36.                  }
  37.                  void waitForFrame() {
  38. -                    _mutex.lock();
  39. +                    std::unique_lock<std::mutex> lck ( _mutex );
  40.                      wantToGrab=true;
  41. -                    _mutex.unlock();
  42. -                    Thcond.Wait();
  43. +                    Thcond.Wait(lck); //this will unlock the mutex and wait atomically
  44.                  };
  45.  
  46.  
  47. diff -ur private/threadcondition.cpp private_new/threadcondition.cpp
  48. --- private/threadcondition.cpp 2014-04-03 18:19:38.000000000 +0200
  49. +++ private_new/threadcondition.cpp 2015-01-07 00:06:11.458808014 +0100
  50. @@ -53,9 +53,9 @@
  51.  //
  52.  //
  53.  ////////////////////////////////
  54. -        void ThreadCondition::Wait() throw ( raspicam::Exception ) {
  55. -            ready=false;
  56. -            std::unique_lock<std::mutex> lck ( mtx );
  57. +        void ThreadCondition::Wait(std::unique_lock<std::mutex>& lck) throw ( raspicam::Exception ) {
  58. +            ready=false; //we're protected by the mutex here
  59. +            //std::unique_lock<std::mutex> lck ( mtx );
  60.              while ( !ready ) cv.wait ( lck );
  61.          }
  62.  
  63. @@ -64,7 +64,7 @@
  64.  //
  65.  ////////////////////////////////
  66.          void ThreadCondition::BroadCast() throw ( raspicam::Exception ) {
  67. -            std::unique_lock<std::mutex> lck ( mtx );
  68. +            //std::unique_lock<std::mutex> lck ( mtx );
  69.              ready = true;
  70.              cv.notify_all();
  71.  
  72. diff -ur private/threadcondition.h private_new/threadcondition.h
  73. --- private/threadcondition.h   2014-04-03 18:19:38.000000000 +0200
  74. +++ private_new/threadcondition.h   2015-01-07 00:06:19.538807768 +0100
  75. @@ -57,7 +57,7 @@
  76.              ThreadCondition() throw ( raspicam::Exception );
  77.  
  78.              /**The thread that call this function waits untils the condition is activated */
  79. -            void Wait() throw ( raspicam::Exception );
  80. +            void Wait(std::unique_lock<std::mutex>& lck) throw ( raspicam::Exception );
  81.  
  82.  
  83.              /**Wake up all threads waiting for this condition */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement