Use C++ thread for demo.c

pull/5817/head
AlexeyAB 5 years ago
parent 9e932d65c5
commit 00193efd83
  1. 12
      src/demo.c
  2. 21
      src/http_stream.cpp
  3. 6
      src/http_stream.h

@ -156,8 +156,8 @@ void demo(char *cfgfile, char *weightfile, float thresh, float hier_thresh, int
flag_exit = 0; flag_exit = 0;
pthread_t fetch_thread; custom_thread_t fetch_thread = NULL;
pthread_t detect_thread; custom_thread_t detect_thread = NULL;
fetch_in_thread(0); fetch_in_thread(0);
det_img = in_img; det_img = in_img;
@ -214,8 +214,8 @@ void demo(char *cfgfile, char *weightfile, float thresh, float hier_thresh, int
int local_nboxes = nboxes; int local_nboxes = nboxes;
detection *local_dets = dets; detection *local_dets = dets;
if (!benchmark) if (pthread_create(&fetch_thread, 0, fetch_in_thread, 0)) error("Thread creation failed"); if (!benchmark) if (custom_create_thread(&fetch_thread, 0, fetch_in_thread, 0)) error("Thread creation failed");
if(pthread_create(&detect_thread, 0, detect_in_thread, 0)) error("Thread creation failed"); if(custom_create_thread(&detect_thread, 0, detect_in_thread, 0)) error("Thread creation failed");
//if (nms) do_nms_obj(local_dets, local_nboxes, l.classes, nms); // bad results //if (nms) do_nms_obj(local_dets, local_nboxes, l.classes, nms); // bad results
if (nms) { if (nms) {
@ -285,9 +285,9 @@ void demo(char *cfgfile, char *weightfile, float thresh, float hier_thresh, int
printf("\n cvWriteFrame \n"); printf("\n cvWriteFrame \n");
} }
pthread_join(detect_thread, 0); custom_join(detect_thread, 0);
if (!benchmark) { if (!benchmark) {
pthread_join(fetch_thread, 0); custom_join(fetch_thread, 0);
free_image(det_s); free_image(det_s);
} }

@ -682,6 +682,27 @@ void show_total_time() {
std::cout << " Total: " << total_time * 1000 << " msec" << std::endl; std::cout << " Total: " << total_time * 1000 << " msec" << std::endl;
} }
int custom_create_thread(custom_thread_t * tid, const custom_attr_t * attr, void *(*func) (void *), void *arg)
{
*tid = (custom_thread_t *)new std::thread(func, arg);
if (tid) return 0;
else return -1;
}
int custom_join(custom_thread_t thread, void **value_ptr)
{
std::thread *ptr = (std::thread *)thread;
if (ptr) {
ptr->join();
delete ptr;
return 0;
}
else printf(" Error: ptr of thread is NULL in custom_join() \n");
return -1;
}
#else // C++11 #else // C++11
#include <iostream> #include <iostream>

@ -18,6 +18,12 @@ int send_http_post_request(char *http_post_host, int server_port, const char *vi
#endif // OPENCV #endif // OPENCV
typedef void* custom_thread_t;
typedef void* custom_attr_t;
int custom_create_thread(custom_thread_t * tid, const custom_attr_t * attr, void *(*func) (void *), void *arg);
int custom_join(custom_thread_t thread, void **value_ptr);
#ifdef __cplusplus #ifdef __cplusplus
} }
#endif #endif

Loading…
Cancel
Save