Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(142)

Unified Diff: webrtc/base/platform_thread.cc

Issue 1476453002: Clean up PlatformThread. (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: IsRunning DCHECK Created 5 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « webrtc/base/platform_thread.h ('k') | webrtc/base/platform_thread_unittest.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: webrtc/base/platform_thread.cc
diff --git a/webrtc/base/platform_thread.cc b/webrtc/base/platform_thread.cc
index af90672a81a7b0c9e9a31f918542d252798a8621..05b7a258c0d58b7d35d16f8f4f09c02f303b0693 100644
--- a/webrtc/base/platform_thread.cc
+++ b/webrtc/base/platform_thread.cc
@@ -76,18 +76,6 @@ void SetCurrentThreadName(const char* name) {
#endif
}
-} // namespace rtc
-
-namespace webrtc {
-
-rtc::scoped_ptr<PlatformThread> PlatformThread::CreateThread(
- ThreadRunFunction func,
- void* obj,
- const char* thread_name) {
- return rtc::scoped_ptr<PlatformThread>(
- new PlatformThread(func, obj, thread_name));
-}
-
namespace {
#if defined(WEBRTC_WIN)
void CALLBACK RaiseFlag(ULONG_PTR param) {
@@ -139,7 +127,7 @@ void* PlatformThread::StartThread(void* param) {
}
#endif // defined(WEBRTC_WIN)
-bool PlatformThread::Start() {
+void PlatformThread::Start() {
RTC_DCHECK(thread_checker_.CalledOnValidThread());
RTC_DCHECK(!thread_) << "Thread already started?";
#if defined(WEBRTC_WIN)
@@ -158,28 +146,33 @@ bool PlatformThread::Start() {
pthread_attr_setstacksize(&attr, 1024 * 1024);
RTC_CHECK_EQ(0, pthread_create(&thread_, &attr, &StartThread, this));
#endif // defined(WEBRTC_WIN)
- return true;
}
-bool PlatformThread::Stop() {
+bool PlatformThread::IsRunning() const {
RTC_DCHECK(thread_checker_.CalledOnValidThread());
#if defined(WEBRTC_WIN)
- if (thread_) {
- // Set stop_ to |true| on the worker thread.
- QueueUserAPC(&RaiseFlag, thread_, reinterpret_cast<ULONG_PTR>(&stop_));
- WaitForSingleObject(thread_, INFINITE);
- CloseHandle(thread_);
- thread_ = nullptr;
- }
+ return thread_ != nullptr;
#else
- if (!thread_)
- return true;
+ return thread_ != 0;
+#endif // defined(WEBRTC_WIN)
+}
+
+void PlatformThread::Stop() {
+ RTC_DCHECK(thread_checker_.CalledOnValidThread());
+ if (!IsRunning())
+ return;
+#if defined(WEBRTC_WIN)
+ // Set stop_ to |true| on the worker thread.
+ QueueUserAPC(&RaiseFlag, thread_, reinterpret_cast<ULONG_PTR>(&stop_));
+ WaitForSingleObject(thread_, INFINITE);
+ CloseHandle(thread_);
+ thread_ = nullptr;
+#else
stop_event_.Set();
RTC_CHECK_EQ(0, pthread_join(thread_, nullptr));
thread_ = 0;
#endif // defined(WEBRTC_WIN)
- return true;
}
void PlatformThread::Run() {
@@ -202,8 +195,9 @@ void PlatformThread::Run() {
bool PlatformThread::SetPriority(ThreadPriority priority) {
RTC_DCHECK(thread_checker_.CalledOnValidThread());
+ RTC_DCHECK(IsRunning());
#if defined(WEBRTC_WIN)
- return thread_ && SetThreadPriority(thread_, priority);
+ return SetThreadPriority(thread_, priority) != FALSE;
#elif defined(__native_client__)
// Setting thread priorities is not supported in NaCl.
return true;
@@ -212,8 +206,6 @@ bool PlatformThread::SetPriority(ThreadPriority priority) {
// thread priorities.
return true;
#else
- if (!thread_)
- return false;
#ifdef WEBRTC_THREAD_RR
const int policy = SCHED_RR;
#else
@@ -255,4 +247,4 @@ bool PlatformThread::SetPriority(ThreadPriority priority) {
#endif // defined(WEBRTC_WIN)
}
-} // namespace webrtc
+} // namespace rtc
« no previous file with comments | « webrtc/base/platform_thread.h ('k') | webrtc/base/platform_thread_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698