From 4eab3ca9bf020df2bb53fa2a36aa4f57d684225c Mon Sep 17 00:00:00 2001 From: zhangmeng <775834166@qq.com> Date: 星期三, 07 八月 2019 17:25:03 +0800 Subject: [PATCH] add rec notify, try catch --- csrc/buz/recorder.cpp | 30 ++++++++++++++++++------------ 1 files changed, 18 insertions(+), 12 deletions(-) diff --git a/csrc/buz/recorder.cpp b/csrc/buz/recorder.cpp index 2cb3b12..1dd71ab 100644 --- a/csrc/buz/recorder.cpp +++ b/csrc/buz/recorder.cpp @@ -31,20 +31,25 @@ ,file_frame_index_(-1) ,file_path_("") ,func_rec_info_(nullptr) + ,thrd_(nullptr) { // logIt("RECODER ID: %s", id_.c_str()); } Recorder::~Recorder(){ - if (out_ && !stop_recorder_.load()){ - stop_recorder_.store(true); - cv_.notify_one(); - while(stop_recorder_.load()){ - logIt("REC WAIT TO QUIT ID %s", id_.c_str()); - sleep(1); - } - }else if (stop_recorder_.load()){ - logIt("REC NORMAL QUIT"); + + try + { + if (thrd_){ + stop_recorder_.store(true); + cv_.notify_one(); + thrd_->join(); + logIt("REC THREAD JOINED, QUIT!!!"); + } + } + catch(const std::exception& e) + { + logIt("RECODER DESTRUCTOR EXCEPTION: ", e.what()); } } @@ -190,9 +195,10 @@ logIt("minduration %d maxduration %d curduration %d", minduration, maxduration, end_frame); - std::thread([&]{ + thrd_.reset(new std::thread([&]{ run_thread(); - }).detach(); + })); + //.detach(); return 0; } @@ -265,4 +271,4 @@ } } } -} \ No newline at end of file +} -- Gitblit v1.8.0