mirror of
https://github.com/kerberos-io/openalpr-base.git
synced 2025-10-06 23:12:45 +08:00
Fixed race condition bug on multithreading
This commit is contained in:
@@ -159,16 +159,13 @@ void plateAnalysisThread(void* arg)
|
|||||||
int loop_count = 0;
|
int loop_count = 0;
|
||||||
while (true)
|
while (true)
|
||||||
{
|
{
|
||||||
|
PlateRegion plateRegion;
|
||||||
if (dispatcher->hasPlate() == false)
|
if (dispatcher->nextPlate(&plateRegion) == false)
|
||||||
break;
|
break;
|
||||||
|
|
||||||
if (dispatcher->config->debugGeneral)
|
if (dispatcher->config->debugGeneral)
|
||||||
cout << "Thread: " << tthread::this_thread::get_id() << " loop " << ++loop_count << endl;
|
cout << "Thread: " << tthread::this_thread::get_id() << " loop " << ++loop_count << endl;
|
||||||
|
|
||||||
// Get a single plate region from the queue
|
|
||||||
PlateRegion plateRegion = dispatcher->nextPlate();
|
|
||||||
|
|
||||||
Mat img = dispatcher->getImageCopy();
|
Mat img = dispatcher->getImageCopy();
|
||||||
|
|
||||||
timespec platestarttime;
|
timespec platestarttime;
|
||||||
|
@@ -109,22 +109,18 @@ class PlateDispatcher
|
|||||||
return img;
|
return img;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool hasPlate()
|
|
||||||
{
|
bool nextPlate(PlateRegion* plateRegion)
|
||||||
bool plateAvailable;
|
|
||||||
mMutex.lock();
|
|
||||||
plateAvailable = plateRegions.size() > 0;
|
|
||||||
mMutex.unlock();
|
|
||||||
return plateAvailable;
|
|
||||||
}
|
|
||||||
PlateRegion nextPlate()
|
|
||||||
{
|
{
|
||||||
tthread::lock_guard<tthread::mutex> guard(mMutex);
|
tthread::lock_guard<tthread::mutex> guard(mMutex);
|
||||||
|
|
||||||
PlateRegion plateRegion = plateRegions[plateRegions.size() - 1];
|
if (plateRegions.size() == 0)
|
||||||
|
return false;
|
||||||
|
|
||||||
|
*plateRegion = plateRegions[plateRegions.size() - 1];
|
||||||
plateRegions.pop_back();
|
plateRegions.pop_back();
|
||||||
|
|
||||||
return plateRegion;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void appendPlate(PlateRegion plate)
|
void appendPlate(PlateRegion plate)
|
||||||
|
Reference in New Issue
Block a user