Use a manual reset event in PosixThread.
This fixes occasional hangs we've been seeing in the past few days. I'm using rtc::Event instead of the EventWrapper, so I'll wait with landing this cl until I've made that change in a separate cl. BUG=2822,4282 R=pbos@webrtc.org Review URL: https://webrtc-codereview.appspot.com/38009004 Cr-Commit-Position: refs/heads/master@{#8293} git-svn-id: http://webrtc.googlecode.com/svn/trunk@8293 4adac7df-926f-26a2-2b94-8c16560cd09d
This commit is contained in:
parent
4c0fd965ce
commit
d0165c62b5
@ -82,7 +82,7 @@ ThreadPosix::ThreadPosix(ThreadRunFunction func, ThreadObj obj,
|
||||
: run_function_(func),
|
||||
obj_(obj),
|
||||
prio_(prio),
|
||||
stop_event_(EventWrapper::Create()),
|
||||
stop_event_(true, false),
|
||||
name_(thread_name ? thread_name : "webrtc"),
|
||||
thread_id_(0),
|
||||
thread_(0) {
|
||||
@ -126,10 +126,10 @@ bool ThreadPosix::Stop() {
|
||||
if (!thread_id_)
|
||||
return true;
|
||||
|
||||
stop_event_->Set();
|
||||
stop_event_.Set();
|
||||
CHECK_EQ(0, pthread_join(thread_, nullptr));
|
||||
thread_id_ = 0;
|
||||
stop_event_->Reset();
|
||||
stop_event_.Reset();
|
||||
|
||||
return true;
|
||||
}
|
||||
@ -175,7 +175,7 @@ void ThreadPosix::Run(ThreadPosix::InitParams* params) {
|
||||
do {
|
||||
if (!run_function_(obj_))
|
||||
break;
|
||||
} while (stop_event_->Wait(0) == kEventTimeout);
|
||||
} while (!stop_event_.Wait(0));
|
||||
}
|
||||
|
||||
} // namespace webrtc
|
||||
|
@ -11,6 +11,7 @@
|
||||
#ifndef WEBRTC_SYSTEM_WRAPPERS_SOURCE_THREAD_POSIX_H_
|
||||
#define WEBRTC_SYSTEM_WRAPPERS_SOURCE_THREAD_POSIX_H_
|
||||
|
||||
#include "webrtc/base/event.h"
|
||||
#include "webrtc/base/scoped_ptr.h"
|
||||
#include "webrtc/base/thread_checker.h"
|
||||
#include "webrtc/system_wrappers/interface/thread_wrapper.h"
|
||||
@ -19,9 +20,6 @@
|
||||
|
||||
namespace webrtc {
|
||||
|
||||
class CriticalSectionWrapper;
|
||||
class EventWrapper;
|
||||
|
||||
int ConvertToSystemPriority(ThreadPriority priority, int min_prio,
|
||||
int max_prio);
|
||||
|
||||
@ -45,8 +43,7 @@ class ThreadPosix : public ThreadWrapper {
|
||||
ThreadRunFunction const run_function_;
|
||||
void* const obj_;
|
||||
ThreadPriority prio_;
|
||||
// TODO(tommi): std::condition_variable?
|
||||
const rtc::scoped_ptr<EventWrapper> stop_event_;
|
||||
rtc::Event stop_event_;
|
||||
const std::string name_;
|
||||
|
||||
pid_t thread_id_;
|
||||
|
Loading…
x
Reference in New Issue
Block a user