Skip to content

Commit e523688

Browse files
committed
Use flag to indicate new frame arrived
1 parent 4daf069 commit e523688

File tree

1 file changed

+10
-6
lines changed

1 file changed

+10
-6
lines changed

deepseg.cc

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,7 @@ typedef struct {
170170
timinginfo_t *pti;
171171
pthread_mutex_t lock_raw;
172172
pthread_mutex_t lock_mask;
173-
pthread_cond_t condition_new_frame;
173+
bool new_frame;
174174
bool running;
175175
} calcinfo_t;
176176

@@ -212,7 +212,7 @@ void init_tensorflow(calcinfo_t &info) {
212212

213213
info.lock_raw = PTHREAD_MUTEX_INITIALIZER;
214214
info.lock_mask = PTHREAD_MUTEX_INITIALIZER;
215-
info.condition_new_frame = PTHREAD_COND_INITIALIZER;
215+
info.new_frame = false;
216216
info.running = false;
217217

218218
info.raw_next = &info.buf1;
@@ -223,12 +223,16 @@ void calc_mask(calcinfo_t &info) {
223223
timestamp_t t = timestamp();
224224
cv::Mat *raw_tmp;
225225

226-
// change frame buffer pointer
227-
pthread_mutex_lock(&info.lock_raw);
226+
// wait for new frame to arrive
228227
timestamp_t t0 = timestamp();
229-
pthread_cond_wait(&info.condition_new_frame, &info.lock_raw); // wait for new frame to arrive
228+
while (!info.new_frame) {
229+
usleep(1000);
230+
}
230231
info.pti->ai_condns = diffnanosecs(timestamp(), t0);
231232
t0 = timestamp();
233+
// change frame buffer pointer
234+
pthread_mutex_lock(&info.lock_raw);
235+
info.new_frame = false;
232236
raw_tmp = info.raw_next;
233237
info.raw_next = info.raw_current;
234238
info.raw_current = raw_tmp;
@@ -525,7 +529,7 @@ int main(int argc, char* argv[]) {
525529
pthread_mutex_lock(&calcinfo.lock_raw);
526530
ti.lockns=timestamp();
527531
*calcinfo.raw_next = raw.clone();
528-
pthread_cond_signal(&calcinfo.condition_new_frame);
532+
calcinfo.new_frame = true;
529533
pthread_mutex_unlock(&calcinfo.lock_raw);
530534
ti.copyns=timestamp();
531535

0 commit comments

Comments
 (0)