Skip to content

Commit bcea983

Browse files
committed
Update clearTasks
1 parent 8476b71 commit bcea983

File tree

1 file changed

+5
-9
lines changed

1 file changed

+5
-9
lines changed

src/dynamsoft_barcode_reader.h

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ class WorkerThread
4343
std::mutex m;
4444
std::condition_variable cv;
4545
std::queue<Task> tasks = {};
46-
volatile bool running;
46+
std::atomic<bool> running;
4747
std::thread t;
4848
};
4949

@@ -60,13 +60,10 @@ typedef struct
6060

6161
void clearTasks(DynamsoftBarcodeReader *self)
6262
{
63-
if (self->worker->tasks.size() > 0)
63+
while (!self->worker->tasks.empty())
6464
{
65-
for (int i = 0; i < self->worker->tasks.size(); i++)
66-
{
67-
free(self->worker->tasks.front().buffer);
68-
self->worker->tasks.pop();
69-
}
65+
free(self->worker->tasks.front().buffer);
66+
self->worker->tasks.pop();
7067
}
7168
}
7269

@@ -120,7 +117,7 @@ static PyObject *DynamsoftBarcodeReader_new(PyTypeObject *type, PyObject *args,
120117
self = (DynamsoftBarcodeReader *)type->tp_alloc(type, 0);
121118
if (self != NULL)
122119
{
123-
self->hBarcode = DBR_CreateInstance();
120+
self->hBarcode = DBR_CreateInstance();
124121
self->callback = NULL;
125122
self->worker = NULL;
126123
}
@@ -515,7 +512,6 @@ static PyObject *addAsyncListener(PyObject *obj, PyObject *args)
515512
self->worker->t = std::thread(&run, self);
516513
}
517514

518-
519515
return Py_BuildValue("i", 0);
520516
}
521517

0 commit comments

Comments
 (0)