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

Unified Diff: webrtc/base/platform_thread.cc

Issue 1908373002: Update PlatformThread to support a couple of new properties. (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: Add one more test Created 4 years, 8 months 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 b6fd8732aaab343e5b1d9c1cacdb563d7fff6108..286bee95f1299823920ec03175962dbf61e9cba8 100644
--- a/webrtc/base/platform_thread.cc
+++ b/webrtc/base/platform_thread.cc
@@ -99,7 +99,8 @@ PlatformThread::PlatformThread(ThreadRunFunction func,
name_(thread_name ? thread_name : "webrtc"),
#if defined(WEBRTC_WIN)
stop_(false),
- thread_(NULL) {
+ thread_(NULL),
+ thread_id_(0) {
#else
stop_event_(false, false),
thread_(0) {
@@ -112,6 +113,7 @@ PlatformThread::~PlatformThread() {
RTC_DCHECK(thread_checker_.CalledOnValidThread());
#if defined(WEBRTC_WIN)
RTC_DCHECK(!thread_);
+ RTC_DCHECK(!thread_id_);
#endif // defined(WEBRTC_WIN)
}
@@ -136,10 +138,10 @@ void PlatformThread::Start() {
// See bug 2902 for background on STACK_SIZE_PARAM_IS_A_RESERVATION.
// Set the reserved stack stack size to 1M, which is the default on Windows
// and Linux.
- DWORD thread_id;
thread_ = ::CreateThread(NULL, 1024 * 1024, &StartThread, this,
- STACK_SIZE_PARAM_IS_A_RESERVATION, &thread_id);
+ STACK_SIZE_PARAM_IS_A_RESERVATION, &thread_id_);
RTC_CHECK(thread_) << "CreateThread failed";
+ RTC_DCHECK(thread_id_);
#else
ThreadAttributes attr;
// Set the stack stack size to 1M.
@@ -157,6 +159,14 @@ bool PlatformThread::IsRunning() const {
#endif // defined(WEBRTC_WIN)
}
+PlatformThreadRef PlatformThread::GetThreadRef() const {
+#if defined(WEBRTC_WIN)
+ return thread_id_;
+#else
+ return thread_;
+#endif // defined(WEBRTC_WIN)
+}
+
void PlatformThread::Stop() {
RTC_DCHECK(thread_checker_.CalledOnValidThread());
if (!IsRunning())
@@ -164,10 +174,13 @@ void PlatformThread::Stop() {
#if defined(WEBRTC_WIN)
// Set stop_ to |true| on the worker thread.
- QueueUserAPC(&RaiseFlag, thread_, reinterpret_cast<ULONG_PTR>(&stop_));
+ bool queued = QueueAPC(&RaiseFlag, reinterpret_cast<ULONG_PTR>(&stop_));
+ // Queuing the APC can fail if the thread is being terminated.
+ RTC_CHECK(queued || GetLastError() == ERROR_GEN_FAILURE);
WaitForSingleObject(thread_, INFINITE);
CloseHandle(thread_);
thread_ = nullptr;
+ thread_id_ = 0;
#else
stop_event_.Set();
RTC_CHECK_EQ(0, pthread_join(thread_, nullptr));
@@ -247,4 +260,13 @@ bool PlatformThread::SetPriority(ThreadPriority priority) {
#endif // defined(WEBRTC_WIN)
}
+#if defined(WEBRTC_WIN)
+bool PlatformThread::QueueAPC(PAPCFUNC function, ULONG_PTR data) {
+ RTC_DCHECK(thread_checker_.CalledOnValidThread());
+ RTC_DCHECK(IsRunning());
+
+ return QueueUserAPC(function, thread_, data) != FALSE;
+}
+#endif
+
} // 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