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
diff --git a/webrtc/system_wrappers/source/thread_posix.cc b/webrtc/system_wrappers/source/thread_posix.cc
index 84ed52d..bbf3b98 100644
--- a/webrtc/system_wrappers/source/thread_posix.cc
+++ b/webrtc/system_wrappers/source/thread_posix.cc
@@ -62,6 +62,7 @@
return low_prio;
}
+// static
void* ThreadPosix::StartThread(void* param) {
static_cast<ThreadPosix*>(param)->Run();
return 0;
@@ -72,8 +73,7 @@
: 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 @@
// 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 c1cf8b5..746984f 100644
--- a/webrtc/system_wrappers/source/thread_posix.h
+++ b/webrtc/system_wrappers/source/thread_posix.h
@@ -42,7 +42,6 @@
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 379ae2a..867369c 100644
--- a/webrtc/video_engine/vie_capturer.cc
+++ b/webrtc/video_engine/vie_capturer.cc
@@ -88,9 +88,7 @@
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 bbf5d53..d1bcf74 100644
--- a/webrtc/video_engine/vie_channel.cc
+++ b/webrtc/video_engine/vie_channel.cc
@@ -1842,16 +1842,7 @@
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 @@
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;
}