From aba9219e5c74e1841932bc15e38e4c83f99f23ee Mon Sep 17 00:00:00 2001 From: "tommi@webrtc.org" Date: Mon, 16 Mar 2015 16:05:50 +0000 Subject: [PATCH] Change ThreadPosix to use an auto-reset event instead of manual reset now that we know the problem we had with EventWrapper::Wait was simply a bug in the EventWrapper. Also removing |started_| since we can just check the thread_ instead. R=pbos@webrtc.org BUG=4413 Review URL: https://webrtc-codereview.appspot.com/47539004 Cr-Commit-Position: refs/heads/master@{#8738} git-svn-id: http://webrtc.googlecode.com/svn/trunk@8738 4adac7df-926f-26a2-2b94-8c16560cd09d --- webrtc/system_wrappers/source/thread_posix.cc | 12 +++++------- webrtc/system_wrappers/source/thread_posix.h | 1 - webrtc/video_engine/vie_capturer.cc | 4 +--- webrtc/video_engine/vie_channel.cc | 19 ++++--------------- 4 files changed, 10 insertions(+), 26 deletions(-) diff --git a/webrtc/system_wrappers/source/thread_posix.cc b/webrtc/system_wrappers/source/thread_posix.cc index 84ed52d168..bbf3b982e7 100644 --- a/webrtc/system_wrappers/source/thread_posix.cc +++ b/webrtc/system_wrappers/source/thread_posix.cc @@ -62,6 +62,7 @@ int ConvertToSystemPriority(ThreadPriority priority, int min_prio, return low_prio; } +// static void* ThreadPosix::StartThread(void* param) { static_cast(param)->Run(); return 0; @@ -72,8 +73,7 @@ ThreadPosix::ThreadPosix(ThreadRunFunction func, ThreadObj obj, : run_function_(func), obj_(obj), prio_(prio), - started_(false), - stop_event_(true, false), + stop_event_(false, false), name_(thread_name ? thread_name : "webrtc"), thread_(0) { DCHECK(name_.length() < kThreadMaxNameLength); @@ -91,25 +91,23 @@ ThreadPosix::~ThreadPosix() { // here. bool ThreadPosix::Start() { DCHECK(thread_checker_.CalledOnValidThread()); + DCHECK(!thread_) << "Thread already started?"; ThreadAttributes attr; // Set the stack stack size to 1M. pthread_attr_setstacksize(&attr, 1024 * 1024); - CHECK_EQ(0, pthread_create(&thread_, &attr, &StartThread, this)); - started_ = true; return true; } bool ThreadPosix::Stop() { DCHECK(thread_checker_.CalledOnValidThread()); - if (!started_) + if (!thread_) return true; stop_event_.Set(); CHECK_EQ(0, pthread_join(thread_, nullptr)); - started_ = false; - stop_event_.Reset(); + thread_ = 0; return true; } diff --git a/webrtc/system_wrappers/source/thread_posix.h b/webrtc/system_wrappers/source/thread_posix.h index c1cf8b5815..746984ffbf 100644 --- a/webrtc/system_wrappers/source/thread_posix.h +++ b/webrtc/system_wrappers/source/thread_posix.h @@ -42,7 +42,6 @@ class ThreadPosix : public ThreadWrapper { ThreadRunFunction const run_function_; void* const obj_; ThreadPriority prio_; - bool started_; rtc::Event stop_event_; const std::string name_; diff --git a/webrtc/video_engine/vie_capturer.cc b/webrtc/video_engine/vie_capturer.cc index 379ae2ab61..867369c1d8 100644 --- a/webrtc/video_engine/vie_capturer.cc +++ b/webrtc/video_engine/vie_capturer.cc @@ -88,9 +88,7 @@ ViECapturer::ViECapturer(int capture_id, overuse_detector_( new OveruseFrameDetector(Clock::GetRealTimeClock(), cpu_overuse_metrics_observer_.get())) { - if (!capture_thread_.Start()) { - assert(false); - } + capture_thread_.Start(); module_process_thread_.RegisterModule(overuse_detector_.get()); } diff --git a/webrtc/video_engine/vie_channel.cc b/webrtc/video_engine/vie_channel.cc index bbf5d535ad..d1bcf74fff 100644 --- a/webrtc/video_engine/vie_channel.cc +++ b/webrtc/video_engine/vie_channel.cc @@ -1842,16 +1842,7 @@ int32_t ViEChannel::StartDecodeThread() { decode_thread_ = ThreadWrapper::CreateThread(ChannelDecodeThreadFunction, this, kHighestPriority, "DecodingThread"); - if (!decode_thread_) { - return -1; - } - - if (decode_thread_->Start() == false) { - delete decode_thread_; - decode_thread_ = NULL; - LOG(LS_ERROR) << "Could not start decode thread."; - return -1; - } + decode_thread_->Start(); return 0; } @@ -1862,12 +1853,10 @@ int32_t ViEChannel::StopDecodeThread() { vcm_->TriggerDecoderShutdown(); - if (decode_thread_->Stop()) { - delete decode_thread_; - } else { - assert(false && "could not stop decode thread"); - } + decode_thread_->Stop(); + delete decode_thread_; decode_thread_ = NULL; + return 0; }