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;
|
return low_prio;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// static
|
||||||
void* ThreadPosix::StartThread(void* param) {
|
void* ThreadPosix::StartThread(void* param) {
|
||||||
static_cast<ThreadPosix*>(param)->Run();
|
static_cast<ThreadPosix*>(param)->Run();
|
||||||
return 0;
|
return 0;
|
||||||
@ -72,8 +73,7 @@ ThreadPosix::ThreadPosix(ThreadRunFunction func, ThreadObj obj,
|
|||||||
: run_function_(func),
|
: run_function_(func),
|
||||||
obj_(obj),
|
obj_(obj),
|
||||||
prio_(prio),
|
prio_(prio),
|
||||||
started_(false),
|
stop_event_(false, false),
|
||||||
stop_event_(true, false),
|
|
||||||
name_(thread_name ? thread_name : "webrtc"),
|
name_(thread_name ? thread_name : "webrtc"),
|
||||||
thread_(0) {
|
thread_(0) {
|
||||||
DCHECK(name_.length() < kThreadMaxNameLength);
|
DCHECK(name_.length() < kThreadMaxNameLength);
|
||||||
@ -91,25 +91,23 @@ ThreadPosix::~ThreadPosix() {
|
|||||||
// here.
|
// here.
|
||||||
bool ThreadPosix::Start() {
|
bool ThreadPosix::Start() {
|
||||||
DCHECK(thread_checker_.CalledOnValidThread());
|
DCHECK(thread_checker_.CalledOnValidThread());
|
||||||
|
DCHECK(!thread_) << "Thread already started?";
|
||||||
|
|
||||||
ThreadAttributes attr;
|
ThreadAttributes attr;
|
||||||
// Set the stack stack size to 1M.
|
// Set the stack stack size to 1M.
|
||||||
pthread_attr_setstacksize(&attr, 1024 * 1024);
|
pthread_attr_setstacksize(&attr, 1024 * 1024);
|
||||||
|
|
||||||
CHECK_EQ(0, pthread_create(&thread_, &attr, &StartThread, this));
|
CHECK_EQ(0, pthread_create(&thread_, &attr, &StartThread, this));
|
||||||
started_ = true;
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool ThreadPosix::Stop() {
|
bool ThreadPosix::Stop() {
|
||||||
DCHECK(thread_checker_.CalledOnValidThread());
|
DCHECK(thread_checker_.CalledOnValidThread());
|
||||||
if (!started_)
|
if (!thread_)
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
stop_event_.Set();
|
stop_event_.Set();
|
||||||
CHECK_EQ(0, pthread_join(thread_, nullptr));
|
CHECK_EQ(0, pthread_join(thread_, nullptr));
|
||||||
started_ = false;
|
thread_ = 0;
|
||||||
stop_event_.Reset();
|
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -42,7 +42,6 @@ class ThreadPosix : public ThreadWrapper {
|
|||||||
ThreadRunFunction const run_function_;
|
ThreadRunFunction const run_function_;
|
||||||
void* const obj_;
|
void* const obj_;
|
||||||
ThreadPriority prio_;
|
ThreadPriority prio_;
|
||||||
bool started_;
|
|
||||||
rtc::Event stop_event_;
|
rtc::Event stop_event_;
|
||||||
const std::string name_;
|
const std::string name_;
|
||||||
|
|
||||||
|
@ -88,9 +88,7 @@ ViECapturer::ViECapturer(int capture_id,
|
|||||||
overuse_detector_(
|
overuse_detector_(
|
||||||
new OveruseFrameDetector(Clock::GetRealTimeClock(),
|
new OveruseFrameDetector(Clock::GetRealTimeClock(),
|
||||||
cpu_overuse_metrics_observer_.get())) {
|
cpu_overuse_metrics_observer_.get())) {
|
||||||
if (!capture_thread_.Start()) {
|
capture_thread_.Start();
|
||||||
assert(false);
|
|
||||||
}
|
|
||||||
module_process_thread_.RegisterModule(overuse_detector_.get());
|
module_process_thread_.RegisterModule(overuse_detector_.get());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1842,16 +1842,7 @@ int32_t ViEChannel::StartDecodeThread() {
|
|||||||
decode_thread_ = ThreadWrapper::CreateThread(ChannelDecodeThreadFunction,
|
decode_thread_ = ThreadWrapper::CreateThread(ChannelDecodeThreadFunction,
|
||||||
this, kHighestPriority,
|
this, kHighestPriority,
|
||||||
"DecodingThread");
|
"DecodingThread");
|
||||||
if (!decode_thread_) {
|
decode_thread_->Start();
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (decode_thread_->Start() == false) {
|
|
||||||
delete decode_thread_;
|
|
||||||
decode_thread_ = NULL;
|
|
||||||
LOG(LS_ERROR) << "Could not start decode thread.";
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1862,12 +1853,10 @@ int32_t ViEChannel::StopDecodeThread() {
|
|||||||
|
|
||||||
vcm_->TriggerDecoderShutdown();
|
vcm_->TriggerDecoderShutdown();
|
||||||
|
|
||||||
if (decode_thread_->Stop()) {
|
decode_thread_->Stop();
|
||||||
delete decode_thread_;
|
delete decode_thread_;
|
||||||
} else {
|
|
||||||
assert(false && "could not stop decode thread");
|
|
||||||
}
|
|
||||||
decode_thread_ = NULL;
|
decode_thread_ = NULL;
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user