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
This commit is contained in:
parent
02d166b735
commit
aba9219e5c
@ -62,6 +62,7 @@ int ConvertToSystemPriority(ThreadPriority priority, int min_prio,
|
||||
return low_prio;
|
||||
}
|
||||
|
||||
// static
|
||||
void* ThreadPosix::StartThread(void* param) {
|
||||
static_cast<ThreadPosix*>(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;
|
||||
}
|
||||
|
@ -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_;
|
||||
|
||||
|
@ -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());
|
||||
}
|
||||
|
||||
|
@ -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;
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user