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_;