From 993e0b0bf9feaf87532186f8ff800b07e4ec3815 Mon Sep 17 00:00:00 2001 From: rajithr Date: Wed, 27 May 2015 15:00:21 +0530 Subject: [PATCH] Fix for a potential data race condition --- modules/objdetect/src/detection_based_tracker.cpp | 26 ++++++----------------- 1 file changed, 7 insertions(+), 19 deletions(-) diff --git a/modules/objdetect/src/detection_based_tracker.cpp b/modules/objdetect/src/detection_based_tracker.cpp index 1f0fb5a..5f1c53c 100644 --- a/modules/objdetect/src/detection_based_tracker.cpp +++ b/modules/objdetect/src/detection_based_tracker.cpp @@ -286,6 +286,13 @@ void* cv::workcycleObjectDetectorFunction(void* p) try{ ((cv::DetectionBasedTracker::SeparateDetectionWork*)p)->lock(); ((cv::DetectionBasedTracker::SeparateDetectionWork*)p)->stateThread = cv::DetectionBasedTracker::SeparateDetectionWork::STATE_THREAD_STOPPED; + ((cv::DetectionBasedTracker::SeparateDetectionWork*)p)->isObjectDetectingReady=false; + ((cv::DetectionBasedTracker::SeparateDetectionWork*)p)->shouldObjectDetectingResultsBeForgot=false; +#ifdef USE_STD_THREADS + objectDetectorThreadStartStop.notify_one(); +#else + pthread_cond_signal(&objectDetectorThreadStartStop); +#endif ((cv::DetectionBasedTracker::SeparateDetectionWork*)p)->unlock(); } catch(...) { LOGE0("DetectionBasedTracker: workcycleObjectDetectorFunction: ERROR concerning pointer, received as the function parameter"); @@ -439,25 +446,6 @@ void cv::DetectionBasedTracker::SeparateDetectionWork::workcycleObjectDetector() objects.clear(); }// while(isWorking()) -#ifdef USE_STD_THREADS - mtx_lock.lock(); -#else - pthread_mutex_lock(&mutex); -#endif - - stateThread=STATE_THREAD_STOPPED; - - isObjectDetectingReady=false; - shouldObjectDetectingResultsBeForgot=false; - -#ifdef USE_STD_THREADS - objectDetectorThreadStartStop.notify_one(); - mtx_lock.unlock(); -#else - pthread_cond_signal(&objectDetectorThreadStartStop); - pthread_mutex_unlock(&mutex); -#endif - LOGI("DetectionBasedTracker::SeparateDetectionWork::workcycleObjectDetector: Returning"); } -- 2.7.4