Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- diff -ur private/private_impl.cpp private_new/private_impl.cpp
- --- private/private_impl.cpp 2014-04-03 18:19:38.000000000 +0200
- +++ private_new/private_impl.cpp 2015-01-07 00:05:24.938809432 +0100
- @@ -468,7 +468,7 @@
- PORT_USERDATA *pData = ( PORT_USERDATA * ) port->userdata;
- bool hasGrabbed=false;
- - pData->_mutex.lock();
- + std::unique_lock<std::mutex> lck ( pData->_mutex );
- if ( pData ) {
- if ( pData->wantToGrab && buffer->length ) {
- mmal_buffer_header_mem_lock ( buffer );
- @@ -479,8 +479,6 @@
- mmal_buffer_header_mem_unlock ( buffer );
- }
- }
- - pData->_mutex.unlock();
- - if ( hasGrabbed ) pData->Thcond.BroadCast(); //wake up waiting client
- // release buffer back to the pool
- mmal_buffer_header_release ( buffer );
- // and send one back to the port (if still open)
- @@ -499,6 +497,8 @@
- if ( pData->pstate->shutterSpeed!=0 )
- mmal_port_parameter_set_uint32 ( pData->pstate->camera_component->control, MMAL_PARAMETER_SHUTTER_SPEED, pData->pstate->shutterSpeed ) ;
- + //pData->_mutex.unlock(); //no need to do this anymore - the Broadcast will unlock the mutex as well
- + if ( hasGrabbed ) pData->Thcond.BroadCast(); //wake up waiting client
- }
- diff -ur private/private_impl.h private_new/private_impl.h
- --- private/private_impl.h 2014-04-03 18:19:38.000000000 +0200
- +++ private_new/private_impl.h 2015-01-07 00:05:44.382808840 +0100
- @@ -61,10 +61,9 @@
- pstate=0;
- }
- void waitForFrame() {
- - _mutex.lock();
- + std::unique_lock<std::mutex> lck ( _mutex );
- wantToGrab=true;
- - _mutex.unlock();
- - Thcond.Wait();
- + Thcond.Wait(lck); //this will unlock the mutex and wait atomically
- };
- diff -ur private/threadcondition.cpp private_new/threadcondition.cpp
- --- private/threadcondition.cpp 2014-04-03 18:19:38.000000000 +0200
- +++ private_new/threadcondition.cpp 2015-01-07 00:06:11.458808014 +0100
- @@ -53,9 +53,9 @@
- //
- //
- ////////////////////////////////
- - void ThreadCondition::Wait() throw ( raspicam::Exception ) {
- - ready=false;
- - std::unique_lock<std::mutex> lck ( mtx );
- + void ThreadCondition::Wait(std::unique_lock<std::mutex>& lck) throw ( raspicam::Exception ) {
- + ready=false; //we're protected by the mutex here
- + //std::unique_lock<std::mutex> lck ( mtx );
- while ( !ready ) cv.wait ( lck );
- }
- @@ -64,7 +64,7 @@
- //
- ////////////////////////////////
- void ThreadCondition::BroadCast() throw ( raspicam::Exception ) {
- - std::unique_lock<std::mutex> lck ( mtx );
- + //std::unique_lock<std::mutex> lck ( mtx );
- ready = true;
- cv.notify_all();
- diff -ur private/threadcondition.h private_new/threadcondition.h
- --- private/threadcondition.h 2014-04-03 18:19:38.000000000 +0200
- +++ private_new/threadcondition.h 2015-01-07 00:06:19.538807768 +0100
- @@ -57,7 +57,7 @@
- ThreadCondition() throw ( raspicam::Exception );
- /**The thread that call this function waits untils the condition is activated */
- - void Wait() throw ( raspicam::Exception );
- + void Wait(std::unique_lock<std::mutex>& lck) throw ( raspicam::Exception );
- /**Wake up all threads waiting for this condition */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement