From 12411ef40e08c5e28ccde54ab3418c96676ffcbc Mon Sep 17 00:00:00 2001 From: pbos Date: Mon, 23 Nov 2015 14:47:56 -0800 Subject: [PATCH] Move ThreadWrapper to ProcessThread in base. Also removes all virtual methods. Permits using a thread from rtc_base_approved (namely event tracing). BUG=webrtc:5158 R=tommi@webrtc.org Review URL: https://codereview.webrtc.org/1469013002 Cr-Commit-Position: refs/heads/master@{#10760} --- webrtc/base/BUILD.gn | 1 + webrtc/base/base.gyp | 1 + webrtc/base/base_tests.gyp | 1 + webrtc/base/platform_thread.cc | 189 +++++++++++++++++- webrtc/base/platform_thread.h | 114 +++++++++-- webrtc/base/platform_thread_types.h | 32 +++ .../platform_thread_unittest.cc} | 12 +- webrtc/base/thread_checker_impl.cc | 2 + webrtc/base/thread_checker_impl.h | 2 +- .../include/incoming_video_stream.h | 4 +- webrtc/common_video/incoming_video_stream.cc | 6 +- .../interface/incoming_video_stream.h | 4 +- .../audio_coding_module_unittest_oldapi.cc | 32 +-- .../modules/audio_coding/main/test/APITest.cc | 34 ++-- .../audio_device/dummy/file_audio_device.cc | 8 +- .../audio_device/dummy/file_audio_device.h | 6 +- .../linux/audio_device_alsa_linux.cc | 12 +- .../linux/audio_device_alsa_linux.h | 6 +- .../linux/audio_device_pulse_linux.cc | 12 +- .../linux/audio_device_pulse_linux.h | 8 +- .../audio_device/mac/audio_device_mac.cc | 6 +- .../audio_device/mac/audio_device_mac.h | 6 +- .../audio_device/test/func_test_manager.cc | 2 +- .../audio_device/win/audio_device_wave_win.cc | 20 +- .../audio_device/win/audio_device_wave_win.h | 4 +- .../audio_processing_impl_locking_unittest.cc | 23 ++- .../rtp_rtcp/test/BWEStandAlone/MatlabPlot.cc | 4 +- .../rtp_rtcp/test/BWEStandAlone/MatlabPlot.h | 4 +- .../test/BWEStandAlone/TestLoadGenerator.cc | 4 +- .../test/BWEStandAlone/TestLoadGenerator.h | 4 +- .../test/BWEStandAlone/TestSenderReceiver.cc | 4 +- .../test/BWEStandAlone/TestSenderReceiver.h | 4 +- .../utility/source/file_recorder_impl.h | 2 +- .../utility/source/process_thread_impl.cc | 4 +- .../utility/source/process_thread_impl.h | 4 +- .../linux/video_capture_linux.cc | 2 +- .../video_capture/linux/video_capture_linux.h | 4 +- .../android/video_render_android_impl.cc | 4 +- .../android/video_render_android_impl.h | 4 +- .../ios/video_render_ios_gles20.h | 4 +- .../ios/video_render_ios_gles20.mm | 4 +- .../video_render/mac/video_render_agl.cc | 14 +- .../video_render/mac/video_render_agl.h | 4 +- .../video_render/mac/video_render_nsopengl.h | 4 +- .../video_render/mac/video_render_nsopengl.mm | 10 +- .../windows/video_render_direct3d9.cc | 4 +- .../windows/video_render_direct3d9.h | 4 +- webrtc/system_wrappers/BUILD.gn | 8 +- .../system_wrappers/include/data_log_impl.h | 4 +- .../system_wrappers/include/thread_wrapper.h | 89 --------- .../source/condition_variable_unittest.cc | 8 +- .../source/critical_section_unittest.cc | 6 +- webrtc/system_wrappers/source/data_log.cc | 4 +- .../source/event_timer_posix.cc | 2 +- .../source/event_timer_posix.h | 4 +- webrtc/system_wrappers/source/thread.cc | 33 --- webrtc/system_wrappers/source/thread_posix.cc | 161 --------------- webrtc/system_wrappers/source/thread_posix.h | 53 ----- .../source/thread_posix_unittest.cc | 30 --- webrtc/system_wrappers/source/thread_win.cc | 101 ---------- webrtc/system_wrappers/source/thread_win.h | 48 ----- webrtc/system_wrappers/source/trace_impl.h | 2 +- webrtc/system_wrappers/system_wrappers.gyp | 6 - .../system_wrappers/system_wrappers_tests.gyp | 5 - .../udp_socket2_manager_win.cc | 2 +- .../udp_socket2_manager_win.h | 6 +- .../test/channel_transport/udp_socket2_win.cc | 10 +- .../udp_socket_manager_posix.cc | 4 +- .../udp_socket_manager_posix.h | 4 +- webrtc/test/direct_transport.cc | 4 +- webrtc/test/direct_transport.h | 4 +- webrtc/test/fake_audio_device.cc | 6 +- webrtc/test/fake_audio_device.h | 4 +- webrtc/test/frame_generator_capturer.cc | 8 +- webrtc/test/frame_generator_capturer.h | 4 +- webrtc/video/rampup_tests.cc | 8 +- webrtc/video/rampup_tests.h | 2 +- webrtc/video/video_capture_input.cc | 6 +- webrtc/video/video_capture_input.h | 4 +- webrtc/video/video_quality_test.cc | 12 +- webrtc/video/video_send_stream_tests.cc | 2 +- webrtc/video_engine/vie_channel.cc | 6 +- webrtc/video_engine/vie_channel.h | 4 +- .../android/android_test/jni/android_test.cc | 6 +- .../auto_test/fakes/conference_transport.cc | 6 +- .../auto_test/fakes/conference_transport.h | 4 +- .../fixtures/after_initialization_fixture.h | 10 +- .../test/auto_test/voe_standard_test.h | 2 +- .../test/auto_test/voe_stress_test.cc | 4 +- .../test/auto_test/voe_stress_test.h | 4 +- 90 files changed, 555 insertions(+), 788 deletions(-) create mode 100644 webrtc/base/platform_thread_types.h rename webrtc/{system_wrappers/source/thread_unittest.cc => base/platform_thread_unittest.cc} (80%) delete mode 100644 webrtc/system_wrappers/include/thread_wrapper.h delete mode 100644 webrtc/system_wrappers/source/thread.cc delete mode 100644 webrtc/system_wrappers/source/thread_posix.cc delete mode 100644 webrtc/system_wrappers/source/thread_posix.h delete mode 100644 webrtc/system_wrappers/source/thread_posix_unittest.cc delete mode 100644 webrtc/system_wrappers/source/thread_win.cc delete mode 100644 webrtc/system_wrappers/source/thread_win.h diff --git a/webrtc/base/BUILD.gn b/webrtc/base/BUILD.gn index 540058b011..956cb181b7 100644 --- a/webrtc/base/BUILD.gn +++ b/webrtc/base/BUILD.gn @@ -124,6 +124,7 @@ static_library("rtc_base_approved") { "platform_file.h", "platform_thread.cc", "platform_thread.h", + "platform_thread_types.h", "safe_conversions.h", "safe_conversions_impl.h", "scoped_ptr.h", diff --git a/webrtc/base/base.gyp b/webrtc/base/base.gyp index c15c1db49a..59f96371ea 100644 --- a/webrtc/base/base.gyp +++ b/webrtc/base/base.gyp @@ -62,6 +62,7 @@ 'platform_file.h', 'platform_thread.cc', 'platform_thread.h', + 'platform_thread_types.h', 'ratetracker.cc', 'ratetracker.h', 'safe_conversions.h', diff --git a/webrtc/base/base_tests.gyp b/webrtc/base/base_tests.gyp index a6dd3d13d8..23b1f9a15e 100644 --- a/webrtc/base/base_tests.gyp +++ b/webrtc/base/base_tests.gyp @@ -80,6 +80,7 @@ 'optional_unittest.cc', 'optionsfile_unittest.cc', 'pathutils_unittest.cc', + 'platform_thread_unittest.cc', 'profiler_unittest.cc', 'proxy_unittest.cc', 'proxydetect_unittest.cc', diff --git a/webrtc/base/platform_thread.cc b/webrtc/base/platform_thread.cc index 4167392363..d32311bcea 100644 --- a/webrtc/base/platform_thread.cc +++ b/webrtc/base/platform_thread.cc @@ -10,8 +10,6 @@ #include "webrtc/base/platform_thread.h" -#include - #include "webrtc/base/checks.h" #if defined(WEBRTC_LINUX) @@ -58,7 +56,6 @@ bool IsThreadRefEqual(const PlatformThreadRef& a, const PlatformThreadRef& b) { } void SetCurrentThreadName(const char* name) { - RTC_DCHECK(strlen(name) < 64); #if defined(WEBRTC_WIN) struct { DWORD dwType; @@ -80,3 +77,189 @@ void SetCurrentThreadName(const char* name) { } } // namespace rtc + +namespace webrtc { + +rtc::scoped_ptr PlatformThread::CreateThread( + ThreadRunFunction func, + void* obj, + const char* thread_name) { + return rtc::scoped_ptr( + new PlatformThread(func, obj, thread_name)); +} + +namespace { +#if defined(WEBRTC_WIN) +void CALLBACK RaiseFlag(ULONG_PTR param) { + *reinterpret_cast(param) = true; +} +#else +struct ThreadAttributes { + ThreadAttributes() { pthread_attr_init(&attr); } + ~ThreadAttributes() { pthread_attr_destroy(&attr); } + pthread_attr_t* operator&() { return &attr; } + pthread_attr_t attr; +}; + +int ConvertToSystemPriority(ThreadPriority priority, + int min_prio, + int max_prio) { + RTC_DCHECK(max_prio - min_prio > 2); + const int top_prio = max_prio - 1; + const int low_prio = min_prio + 1; + + switch (priority) { + case kLowPriority: + return low_prio; + case kNormalPriority: + // The -1 ensures that the kHighPriority is always greater or equal to + // kNormalPriority. + return (low_prio + top_prio - 1) / 2; + case kHighPriority: + return std::max(top_prio - 2, low_prio); + case kHighestPriority: + return std::max(top_prio - 1, low_prio); + case kRealtimePriority: + return top_prio; + } + RTC_DCHECK(false); + return low_prio; +} +#endif // defined(WEBRTC_WIN) +} + +PlatformThread::PlatformThread(ThreadRunFunction func, + void* obj, + const char* thread_name) + : run_function_(func), + obj_(obj), + name_(thread_name ? thread_name : "webrtc"), +#if defined(WEBRTC_WIN) + stop_(false), + thread_(NULL) { +#else + stop_event_(false, false), + thread_(0) { +#endif // defined(WEBRTC_WIN) + RTC_DCHECK(func); + RTC_DCHECK(name_.length() < 64); +} + +PlatformThread::~PlatformThread() { + RTC_DCHECK(thread_checker_.CalledOnValidThread()); +#if defined(WEBRTC_WIN) + RTC_DCHECK(!thread_); +#endif // defined(WEBRTC_WIN) +} + +#if defined(WEBRTC_WIN) +DWORD WINAPI PlatformThread::StartThread(void* param) { + static_cast(param)->Run(); + return 0; +} +#else +void* PlatformThread::StartThread(void* param) { + static_cast(param)->Run(); + return 0; +} +#endif // defined(WEBRTC_WIN) + +bool PlatformThread::Start() { + RTC_DCHECK(thread_checker_.CalledOnValidThread()); + RTC_DCHECK(!thread_) << "Thread already started?"; +#if defined(WEBRTC_WIN) + stop_ = false; + + // 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); + RTC_CHECK(thread_) << "CreateThread failed"; +#else + ThreadAttributes attr; + // Set the stack stack size to 1M. + 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() { + RTC_DCHECK(thread_checker_.CalledOnValidThread()); +#if defined(WEBRTC_WIN) + if (thread_) { + // Set stop_ to |true| on the worker thread. + QueueUserAPC(&RaiseFlag, thread_, reinterpret_cast(&stop_)); + WaitForSingleObject(thread_, INFINITE); + CloseHandle(thread_); + thread_ = nullptr; + } +#else + if (!thread_) + return true; + + stop_event_.Set(); + RTC_CHECK_EQ(0, pthread_join(thread_, nullptr)); + thread_ = 0; +#endif // defined(WEBRTC_WIN) + return true; +} + +void PlatformThread::Run() { + if (!name_.empty()) + rtc::SetCurrentThreadName(name_.c_str()); + do { + // The interface contract of Start/Stop is that for a successfull call to + // Start, there should be at least one call to the run function. So we + // call the function before checking |stop_|. + if (!run_function_(obj_)) + break; +#if defined(WEBRTC_WIN) + // Alertable sleep to permit RaiseFlag to run and update |stop_|. + SleepEx(0, true); + } while (!stop_); +#else + } while (!stop_event_.Wait(0)); +#endif // defined(WEBRTC_WIN) +} + +bool PlatformThread::SetPriority(ThreadPriority priority) { + RTC_DCHECK(thread_checker_.CalledOnValidThread()); +#if defined(WEBRTC_WIN) + return thread_ && SetThreadPriority(thread_, priority); +#else + if (!thread_) + return false; +#if defined(WEBRTC_CHROMIUM_BUILD) && defined(WEBRTC_LINUX) + // TODO(tommi): Switch to the same mechanism as Chromium uses for + // changing thread priorities. + return true; +#else +#ifdef WEBRTC_THREAD_RR + const int policy = SCHED_RR; +#else + const int policy = SCHED_FIFO; +#endif + const int min_prio = sched_get_priority_min(policy); + const int max_prio = sched_get_priority_max(policy); + if (min_prio == -1 || max_prio == -1) { + return false; + } + + if (max_prio - min_prio <= 2) + return false; + + sched_param param; + param.sched_priority = ConvertToSystemPriority(priority, min_prio, max_prio); + if (pthread_setschedparam(thread_, policy, ¶m) != 0) { + return false; + } + + return true; +#endif // defined(WEBRTC_CHROMIUM_BUILD) && defined(WEBRTC_LINUX) +#endif // defined(WEBRTC_WIN) +} + +} // namespace webrtc diff --git a/webrtc/base/platform_thread.h b/webrtc/base/platform_thread.h index 50033b3928..e2d9b337e4 100644 --- a/webrtc/base/platform_thread.h +++ b/webrtc/base/platform_thread.h @@ -11,24 +11,16 @@ #ifndef WEBRTC_BASE_PLATFORM_THREAD_H_ #define WEBRTC_BASE_PLATFORM_THREAD_H_ -#if defined(WEBRTC_WIN) -#include -#include -#elif defined(WEBRTC_POSIX) -#include -#include -#endif +#include + +#include "webrtc/base/constructormagic.h" +#include "webrtc/base/event.h" +#include "webrtc/base/platform_thread_types.h" +#include "webrtc/base/scoped_ptr.h" +#include "webrtc/base/thread_checker.h" namespace rtc { -#if defined(WEBRTC_WIN) -typedef DWORD PlatformThreadId; -typedef DWORD PlatformThreadRef; -#elif defined(WEBRTC_POSIX) -typedef pid_t PlatformThreadId; -typedef pthread_t PlatformThreadRef; -#endif - PlatformThreadId CurrentThreadId(); PlatformThreadRef CurrentThreadRef(); @@ -40,4 +32,96 @@ void SetCurrentThreadName(const char* name); } // namespace rtc +// TODO(pbos): Merge with namespace rtc. +namespace webrtc { + +// Callback function that the spawned thread will enter once spawned. +// A return value of false is interpreted as that the function has no +// more work to do and that the thread can be released. +typedef bool (*ThreadRunFunction)(void*); + +enum ThreadPriority { +#ifdef WEBRTC_WIN + kLowPriority = THREAD_PRIORITY_BELOW_NORMAL, + kNormalPriority = THREAD_PRIORITY_NORMAL, + kHighPriority = THREAD_PRIORITY_ABOVE_NORMAL, + kHighestPriority = THREAD_PRIORITY_HIGHEST, + kRealtimePriority = THREAD_PRIORITY_TIME_CRITICAL +#else + kLowPriority = 1, + kNormalPriority = 2, + kHighPriority = 3, + kHighestPriority = 4, + kRealtimePriority = 5 +#endif +}; + +// Represents a simple worker thread. The implementation must be assumed +// to be single threaded, meaning that all methods of the class, must be +// called from the same thread, including instantiation. +// TODO(tommi): There's no need for this to be a virtual interface since there's +// only ever a single implementation of it. +class PlatformThread { + public: + PlatformThread(ThreadRunFunction func, void* obj, const char* thread_name); + virtual ~PlatformThread(); + + // Factory method. Constructor disabled. + // + // func Pointer to a, by user, specified callback function. + // obj Object associated with the thread. Passed in the callback + // function. + // prio Thread priority. May require root/admin rights. + // thread_name NULL terminated thread name, will be visable in the Windows + // debugger. + // TODO(pbos): Move users onto explicit initialization/member ownership + // instead of additional heap allocation due to CreateThread. + static rtc::scoped_ptr CreateThread(ThreadRunFunction func, + void* obj, + const char* thread_name); + + // Tries to spawns a thread and returns true if that was successful. + // Additionally, it tries to set thread priority according to the priority + // from when CreateThread was called. However, failure to set priority will + // not result in a false return value. + // TODO(pbos): Make void not war. + bool Start(); + + // Stops the spawned thread and waits for it to be reclaimed with a timeout + // of two seconds. Will return false if the thread was not reclaimed. + // Multiple tries to Stop are allowed (e.g. to wait longer than 2 seconds). + // It's ok to call Stop() even if the spawned thread has been reclaimed. + // TODO(pbos): Make void not war. + bool Stop(); + + // Set the priority of the worker thread. Must be called when thread + // is running. + bool SetPriority(ThreadPriority priority); + + private: + void Run(); + + ThreadRunFunction const run_function_; + void* const obj_; + // TODO(pbos): Make sure call sites use string literals and update to a const + // char* instead of a std::string. + const std::string name_; + rtc::ThreadChecker thread_checker_; +#if defined(WEBRTC_WIN) + static DWORD WINAPI StartThread(void* param); + + bool stop_; + HANDLE thread_; +#else + static void* StartThread(void* param); + + rtc::Event stop_event_; + + pthread_t thread_; +#endif // defined(WEBRTC_WIN) + RTC_DISALLOW_COPY_AND_ASSIGN(PlatformThread); +}; + +} // namespace webrtc + #endif // WEBRTC_BASE_PLATFORM_THREAD_H_ diff --git a/webrtc/base/platform_thread_types.h b/webrtc/base/platform_thread_types.h new file mode 100644 index 0000000000..546fffd96d --- /dev/null +++ b/webrtc/base/platform_thread_types.h @@ -0,0 +1,32 @@ +/* + * Copyright (c) 2015 The WebRTC project authors. All Rights Reserved. + * + * Use of this source code is governed by a BSD-style license + * that can be found in the LICENSE file in the root of the source + * tree. An additional intellectual property rights grant can be found + * in the file PATENTS. All contributing project authors may + * be found in the AUTHORS file in the root of the source tree. + */ + +#ifndef WEBRTC_BASE_PLATFORM_THREAD_TYPES_H_ +#define WEBRTC_BASE_PLATFORM_THREAD_TYPES_H_ + +#if defined(WEBRTC_WIN) +#include +#include +#elif defined(WEBRTC_POSIX) +#include +#include +#endif + +namespace rtc { +#if defined(WEBRTC_WIN) +typedef DWORD PlatformThreadId; +typedef DWORD PlatformThreadRef; +#elif defined(WEBRTC_POSIX) +typedef pid_t PlatformThreadId; +typedef pthread_t PlatformThreadRef; +#endif +} // namespace rtc + +#endif // WEBRTC_BASE_PLATFORM_THREAD_TYPES_H_ diff --git a/webrtc/system_wrappers/source/thread_unittest.cc b/webrtc/base/platform_thread_unittest.cc similarity index 80% rename from webrtc/system_wrappers/source/thread_unittest.cc rename to webrtc/base/platform_thread_unittest.cc index c8e180ba32..ffb60b5324 100644 --- a/webrtc/system_wrappers/source/thread_unittest.cc +++ b/webrtc/base/platform_thread_unittest.cc @@ -8,7 +8,7 @@ * be found in the AUTHORS file in the root of the source tree. */ -#include "webrtc/system_wrappers/include/thread_wrapper.h" +#include "webrtc/base/platform_thread.h" #include "testing/gtest/include/gtest/gtest.h" #include "webrtc/base/scoped_ptr.h" @@ -22,9 +22,9 @@ bool NullRunFunction(void* obj) { return true; } -TEST(ThreadTest, StartStop) { - rtc::scoped_ptr thread = ThreadWrapper::CreateThread( - &NullRunFunction, nullptr, "ThreadTest"); +TEST(PlatformThreadTest, StartStop) { + rtc::scoped_ptr thread = PlatformThread::CreateThread( + &NullRunFunction, nullptr, "PlatformThreadTest"); ASSERT_TRUE(thread->Start()); EXPECT_TRUE(thread->Stop()); } @@ -37,9 +37,9 @@ bool SetFlagRunFunction(void* obj) { return true; } -TEST(ThreadTest, RunFunctionIsCalled) { +TEST(PlatformThreadTest, RunFunctionIsCalled) { bool flag = false; - rtc::scoped_ptr thread = ThreadWrapper::CreateThread( + rtc::scoped_ptr thread = PlatformThread::CreateThread( &SetFlagRunFunction, &flag, "RunFunctionIsCalled"); ASSERT_TRUE(thread->Start()); diff --git a/webrtc/base/thread_checker_impl.cc b/webrtc/base/thread_checker_impl.cc index ea88308772..79be606445 100644 --- a/webrtc/base/thread_checker_impl.cc +++ b/webrtc/base/thread_checker_impl.cc @@ -12,6 +12,8 @@ #include "webrtc/base/thread_checker_impl.h" +#include "webrtc/base/platform_thread.h" + namespace rtc { ThreadCheckerImpl::ThreadCheckerImpl() : valid_thread_(CurrentThreadRef()) { diff --git a/webrtc/base/thread_checker_impl.h b/webrtc/base/thread_checker_impl.h index 7b39ada0ca..045583591d 100644 --- a/webrtc/base/thread_checker_impl.h +++ b/webrtc/base/thread_checker_impl.h @@ -14,7 +14,7 @@ #define WEBRTC_BASE_THREAD_CHECKER_IMPL_H_ #include "webrtc/base/criticalsection.h" -#include "webrtc/base/platform_thread.h" +#include "webrtc/base/platform_thread_types.h" namespace rtc { diff --git a/webrtc/common_video/include/incoming_video_stream.h b/webrtc/common_video/include/incoming_video_stream.h index cd0d65385e..93bc1baf5b 100644 --- a/webrtc/common_video/include/incoming_video_stream.h +++ b/webrtc/common_video/include/incoming_video_stream.h @@ -18,7 +18,7 @@ namespace webrtc { class CriticalSectionWrapper; class EventTimerWrapper; -class ThreadWrapper; +class PlatformThread; class VideoRenderCallback { public: @@ -77,7 +77,7 @@ class IncomingVideoStream : public VideoRenderCallback { const rtc::scoped_ptr stream_critsect_; const rtc::scoped_ptr thread_critsect_; const rtc::scoped_ptr buffer_critsect_; - rtc::scoped_ptr incoming_render_thread_ + rtc::scoped_ptr incoming_render_thread_ GUARDED_BY(thread_critsect_); rtc::scoped_ptr deliver_buffer_event_; diff --git a/webrtc/common_video/incoming_video_stream.cc b/webrtc/common_video/incoming_video_stream.cc index a4b25fcd2e..78fc38695c 100644 --- a/webrtc/common_video/incoming_video_stream.cc +++ b/webrtc/common_video/incoming_video_stream.cc @@ -21,11 +21,11 @@ #include #endif +#include "webrtc/base/platform_thread.h" #include "webrtc/common_video/libyuv/include/webrtc_libyuv.h" #include "webrtc/common_video/video_render_frames.h" #include "webrtc/system_wrappers/include/critical_section_wrapper.h" #include "webrtc/system_wrappers/include/event_wrapper.h" -#include "webrtc/system_wrappers/include/thread_wrapper.h" #include "webrtc/system_wrappers/include/tick_util.h" #include "webrtc/system_wrappers/include/trace.h" @@ -131,7 +131,7 @@ int32_t IncomingVideoStream::Start() { CriticalSectionScoped csT(thread_critsect_.get()); assert(incoming_render_thread_ == NULL); - incoming_render_thread_ = ThreadWrapper::CreateThread( + incoming_render_thread_ = PlatformThread::CreateThread( IncomingVideoStreamThreadFun, this, "IncomingVideoStreamThread"); if (!incoming_render_thread_) { return -1; @@ -155,7 +155,7 @@ int32_t IncomingVideoStream::Stop() { return 0; } - ThreadWrapper* thread = NULL; + PlatformThread* thread = NULL; { CriticalSectionScoped cs_thread(thread_critsect_.get()); if (incoming_render_thread_) { diff --git a/webrtc/common_video/interface/incoming_video_stream.h b/webrtc/common_video/interface/incoming_video_stream.h index 886dae58e6..00519ec2cc 100644 --- a/webrtc/common_video/interface/incoming_video_stream.h +++ b/webrtc/common_video/interface/incoming_video_stream.h @@ -20,7 +20,7 @@ namespace webrtc { class CriticalSectionWrapper; class EventTimerWrapper; -class ThreadWrapper; +class PlatformThread; class VideoRenderCallback { public: @@ -79,7 +79,7 @@ class IncomingVideoStream : public VideoRenderCallback { const rtc::scoped_ptr stream_critsect_; const rtc::scoped_ptr thread_critsect_; const rtc::scoped_ptr buffer_critsect_; - rtc::scoped_ptr incoming_render_thread_ + rtc::scoped_ptr incoming_render_thread_ GUARDED_BY(thread_critsect_); rtc::scoped_ptr deliver_buffer_event_; diff --git a/webrtc/modules/audio_coding/main/acm2/audio_coding_module_unittest_oldapi.cc b/webrtc/modules/audio_coding/main/acm2/audio_coding_module_unittest_oldapi.cc index 06cc432374..f14dcf3dea 100644 --- a/webrtc/modules/audio_coding/main/acm2/audio_coding_module_unittest_oldapi.cc +++ b/webrtc/modules/audio_coding/main/acm2/audio_coding_module_unittest_oldapi.cc @@ -13,6 +13,7 @@ #include "testing/gtest/include/gtest/gtest.h" #include "webrtc/base/md5digest.h" +#include "webrtc/base/platform_thread.h" #include "webrtc/base/scoped_ptr.h" #include "webrtc/base/thread_annotations.h" #include "webrtc/modules/audio_coding/codecs/audio_encoder.h" @@ -38,7 +39,6 @@ #include "webrtc/system_wrappers/include/critical_section_wrapper.h" #include "webrtc/system_wrappers/include/event_wrapper.h" #include "webrtc/system_wrappers/include/sleep.h" -#include "webrtc/system_wrappers/include/thread_wrapper.h" #include "webrtc/test/testsupport/fileutils.h" #include "webrtc/test/testsupport/gtest_disable.h" @@ -457,11 +457,13 @@ class AudioCodingModuleMtTestOldApi : public AudioCodingModuleTestOldApi { AudioCodingModuleMtTestOldApi() : AudioCodingModuleTestOldApi(), - send_thread_(ThreadWrapper::CreateThread(CbSendThread, this, "send")), - insert_packet_thread_(ThreadWrapper::CreateThread( - CbInsertPacketThread, this, "insert_packet")), - pull_audio_thread_(ThreadWrapper::CreateThread( - CbPullAudioThread, this, "pull_audio")), + send_thread_(PlatformThread::CreateThread(CbSendThread, this, "send")), + insert_packet_thread_(PlatformThread::CreateThread(CbInsertPacketThread, + this, + "insert_packet")), + pull_audio_thread_(PlatformThread::CreateThread(CbPullAudioThread, + this, + "pull_audio")), test_complete_(EventWrapper::Create()), send_count_(0), insert_packet_count_(0), @@ -571,9 +573,9 @@ class AudioCodingModuleMtTestOldApi : public AudioCodingModuleTestOldApi { return true; } - rtc::scoped_ptr send_thread_; - rtc::scoped_ptr insert_packet_thread_; - rtc::scoped_ptr pull_audio_thread_; + rtc::scoped_ptr send_thread_; + rtc::scoped_ptr insert_packet_thread_; + rtc::scoped_ptr pull_audio_thread_; const rtc::scoped_ptr test_complete_; int send_count_; int insert_packet_count_; @@ -701,11 +703,11 @@ class AcmReRegisterIsacMtTestOldApi : public AudioCodingModuleTestOldApi { AcmReRegisterIsacMtTestOldApi() : AudioCodingModuleTestOldApi(), receive_thread_( - ThreadWrapper::CreateThread(CbReceiveThread, this, "receive")), + PlatformThread::CreateThread(CbReceiveThread, this, "receive")), codec_registration_thread_( - ThreadWrapper::CreateThread(CbCodecRegistrationThread, - this, - "codec_registration")), + PlatformThread::CreateThread(CbCodecRegistrationThread, + this, + "codec_registration")), test_complete_(EventWrapper::Create()), crit_sect_(CriticalSectionWrapper::CreateCriticalSection()), codec_registered_(false), @@ -829,8 +831,8 @@ class AcmReRegisterIsacMtTestOldApi : public AudioCodingModuleTestOldApi { return true; } - rtc::scoped_ptr receive_thread_; - rtc::scoped_ptr codec_registration_thread_; + rtc::scoped_ptr receive_thread_; + rtc::scoped_ptr codec_registration_thread_; const rtc::scoped_ptr test_complete_; const rtc::scoped_ptr crit_sect_; bool codec_registered_ GUARDED_BY(crit_sect_); diff --git a/webrtc/modules/audio_coding/main/test/APITest.cc b/webrtc/modules/audio_coding/main/test/APITest.cc index dec14738df..88ad7e2a76 100644 --- a/webrtc/modules/audio_coding/main/test/APITest.cc +++ b/webrtc/modules/audio_coding/main/test/APITest.cc @@ -20,13 +20,13 @@ #include #include "testing/gtest/include/gtest/gtest.h" +#include "webrtc/base/platform_thread.h" #include "webrtc/common.h" #include "webrtc/common_types.h" #include "webrtc/engine_configurations.h" #include "webrtc/modules/audio_coding/main/acm2/acm_common_defs.h" #include "webrtc/modules/audio_coding/main/test/utility.h" #include "webrtc/system_wrappers/include/event_wrapper.h" -#include "webrtc/system_wrappers/include/thread_wrapper.h" #include "webrtc/system_wrappers/include/tick_util.h" #include "webrtc/system_wrappers/include/trace.h" #include "webrtc/test/testsupport/fileutils.h" @@ -522,37 +522,37 @@ void APITest::Perform() { //--- THREADS // A // PUSH - rtc::scoped_ptr myPushAudioThreadA = - ThreadWrapper::CreateThread(PushAudioThreadA, this, "PushAudioThreadA"); + rtc::scoped_ptr myPushAudioThreadA = + PlatformThread::CreateThread(PushAudioThreadA, this, "PushAudioThreadA"); CHECK_THREAD_NULLITY(myPushAudioThreadA, "Unable to start A::PUSH thread"); // PULL - rtc::scoped_ptr myPullAudioThreadA = - ThreadWrapper::CreateThread(PullAudioThreadA, this, "PullAudioThreadA"); + rtc::scoped_ptr myPullAudioThreadA = + PlatformThread::CreateThread(PullAudioThreadA, this, "PullAudioThreadA"); CHECK_THREAD_NULLITY(myPullAudioThreadA, "Unable to start A::PULL thread"); // Process - rtc::scoped_ptr myProcessThreadA = ThreadWrapper::CreateThread( - ProcessThreadA, this, "ProcessThreadA"); + rtc::scoped_ptr myProcessThreadA = + PlatformThread::CreateThread(ProcessThreadA, this, "ProcessThreadA"); CHECK_THREAD_NULLITY(myProcessThreadA, "Unable to start A::Process thread"); // API - rtc::scoped_ptr myAPIThreadA = ThreadWrapper::CreateThread( - APIThreadA, this, "APIThreadA"); + rtc::scoped_ptr myAPIThreadA = + PlatformThread::CreateThread(APIThreadA, this, "APIThreadA"); CHECK_THREAD_NULLITY(myAPIThreadA, "Unable to start A::API thread"); // B // PUSH - rtc::scoped_ptr myPushAudioThreadB = - ThreadWrapper::CreateThread(PushAudioThreadB, this, "PushAudioThreadB"); + rtc::scoped_ptr myPushAudioThreadB = + PlatformThread::CreateThread(PushAudioThreadB, this, "PushAudioThreadB"); CHECK_THREAD_NULLITY(myPushAudioThreadB, "Unable to start B::PUSH thread"); // PULL - rtc::scoped_ptr myPullAudioThreadB = - ThreadWrapper::CreateThread(PullAudioThreadB, this, "PullAudioThreadB"); + rtc::scoped_ptr myPullAudioThreadB = + PlatformThread::CreateThread(PullAudioThreadB, this, "PullAudioThreadB"); CHECK_THREAD_NULLITY(myPullAudioThreadB, "Unable to start B::PULL thread"); // Process - rtc::scoped_ptr myProcessThreadB = ThreadWrapper::CreateThread( - ProcessThreadB, this, "ProcessThreadB"); + rtc::scoped_ptr myProcessThreadB = + PlatformThread::CreateThread(ProcessThreadB, this, "ProcessThreadB"); CHECK_THREAD_NULLITY(myProcessThreadB, "Unable to start B::Process thread"); // API - rtc::scoped_ptr myAPIThreadB = ThreadWrapper::CreateThread( - APIThreadB, this, "APIThreadB"); + rtc::scoped_ptr myAPIThreadB = + PlatformThread::CreateThread(APIThreadB, this, "APIThreadB"); CHECK_THREAD_NULLITY(myAPIThreadB, "Unable to start B::API thread"); //_apiEventA->StartTimer(true, 5000); diff --git a/webrtc/modules/audio_device/dummy/file_audio_device.cc b/webrtc/modules/audio_device/dummy/file_audio_device.cc index eb3d042ad7..d59eae2ae8 100644 --- a/webrtc/modules/audio_device/dummy/file_audio_device.cc +++ b/webrtc/modules/audio_device/dummy/file_audio_device.cc @@ -7,9 +7,9 @@ * in the file PATENTS. All contributing project authors may * be found in the AUTHORS file in the root of the source tree. */ +#include "webrtc/base/platform_thread.h" #include "webrtc/modules/audio_device/dummy/file_audio_device.h" #include "webrtc/system_wrappers/include/sleep.h" -#include "webrtc/system_wrappers/include/thread_wrapper.h" namespace webrtc { @@ -214,8 +214,8 @@ int32_t FileAudioDevice::StartPlayout() { } const char* threadName = "webrtc_audio_module_play_thread"; - _ptrThreadPlay = ThreadWrapper::CreateThread(PlayThreadFunc, this, - threadName); + _ptrThreadPlay = + PlatformThread::CreateThread(PlayThreadFunc, this, threadName); if (!_ptrThreadPlay->Start()) { _ptrThreadPlay.reset(); _playing = false; @@ -277,7 +277,7 @@ int32_t FileAudioDevice::StartRecording() { } const char* threadName = "webrtc_audio_module_capture_thread"; - _ptrThreadRec = ThreadWrapper::CreateThread(RecThreadFunc, this, threadName); + _ptrThreadRec = PlatformThread::CreateThread(RecThreadFunc, this, threadName); if (!_ptrThreadRec->Start()) { _ptrThreadRec.reset(); diff --git a/webrtc/modules/audio_device/dummy/file_audio_device.h b/webrtc/modules/audio_device/dummy/file_audio_device.h index 0e1665ea72..a8a71ca62b 100644 --- a/webrtc/modules/audio_device/dummy/file_audio_device.h +++ b/webrtc/modules/audio_device/dummy/file_audio_device.h @@ -22,7 +22,7 @@ namespace webrtc { class EventWrapper; -class ThreadWrapper; +class PlatformThread; // This is a fake audio device which plays audio from a file as its microphone // and plays out into a file. @@ -178,8 +178,8 @@ class FileAudioDevice : public AudioDeviceGeneric { size_t _recordingFramesIn10MS; size_t _playoutFramesIn10MS; - rtc::scoped_ptr _ptrThreadRec; - rtc::scoped_ptr _ptrThreadPlay; + rtc::scoped_ptr _ptrThreadRec; + rtc::scoped_ptr _ptrThreadPlay; bool _playing; bool _recording; diff --git a/webrtc/modules/audio_device/linux/audio_device_alsa_linux.cc b/webrtc/modules/audio_device/linux/audio_device_alsa_linux.cc index 8fa4fdf6f0..b8c19a28af 100644 --- a/webrtc/modules/audio_device/linux/audio_device_alsa_linux.cc +++ b/webrtc/modules/audio_device/linux/audio_device_alsa_linux.cc @@ -207,7 +207,7 @@ int32_t AudioDeviceLinuxALSA::Terminate() // RECORDING if (_ptrThreadRec) { - ThreadWrapper* tmpThread = _ptrThreadRec.release(); + PlatformThread* tmpThread = _ptrThreadRec.release(); _critSect.Leave(); tmpThread->Stop(); @@ -219,7 +219,7 @@ int32_t AudioDeviceLinuxALSA::Terminate() // PLAYOUT if (_ptrThreadPlay) { - ThreadWrapper* tmpThread = _ptrThreadPlay.release(); + PlatformThread* tmpThread = _ptrThreadPlay.release(); _critSect.Leave(); tmpThread->Stop(); @@ -1364,8 +1364,8 @@ int32_t AudioDeviceLinuxALSA::StartRecording() } // RECORDING const char* threadName = "webrtc_audio_module_capture_thread"; - _ptrThreadRec = ThreadWrapper::CreateThread( - RecThreadFunc, this, threadName); + _ptrThreadRec = + PlatformThread::CreateThread(RecThreadFunc, this, threadName); if (!_ptrThreadRec->Start()) { @@ -1518,8 +1518,8 @@ int32_t AudioDeviceLinuxALSA::StartPlayout() // PLAYOUT const char* threadName = "webrtc_audio_module_play_thread"; - _ptrThreadPlay = ThreadWrapper::CreateThread(PlayThreadFunc, this, - threadName); + _ptrThreadPlay = + PlatformThread::CreateThread(PlayThreadFunc, this, threadName); if (!_ptrThreadPlay->Start()) { WEBRTC_TRACE(kTraceCritical, kTraceAudioDevice, _id, diff --git a/webrtc/modules/audio_device/linux/audio_device_alsa_linux.h b/webrtc/modules/audio_device/linux/audio_device_alsa_linux.h index e2391a0456..c61dc86b5a 100644 --- a/webrtc/modules/audio_device/linux/audio_device_alsa_linux.h +++ b/webrtc/modules/audio_device/linux/audio_device_alsa_linux.h @@ -11,10 +11,10 @@ #ifndef WEBRTC_AUDIO_DEVICE_AUDIO_DEVICE_ALSA_LINUX_H #define WEBRTC_AUDIO_DEVICE_AUDIO_DEVICE_ALSA_LINUX_H +#include "webrtc/base/platform_thread.h" #include "webrtc/modules/audio_device/audio_device_generic.h" #include "webrtc/modules/audio_device/linux/audio_mixer_manager_alsa_linux.h" #include "webrtc/system_wrappers/include/critical_section_wrapper.h" -#include "webrtc/system_wrappers/include/thread_wrapper.h" #if defined(USE_X11) #include @@ -185,8 +185,8 @@ private: CriticalSectionWrapper& _critSect; - rtc::scoped_ptr _ptrThreadRec; - rtc::scoped_ptr _ptrThreadPlay; + rtc::scoped_ptr _ptrThreadRec; + rtc::scoped_ptr _ptrThreadPlay; int32_t _id; diff --git a/webrtc/modules/audio_device/linux/audio_device_pulse_linux.cc b/webrtc/modules/audio_device/linux/audio_device_pulse_linux.cc index 929a758e40..7970ef7c79 100644 --- a/webrtc/modules/audio_device/linux/audio_device_pulse_linux.cc +++ b/webrtc/modules/audio_device/linux/audio_device_pulse_linux.cc @@ -201,8 +201,8 @@ int32_t AudioDeviceLinuxPulse::Init() // RECORDING const char* threadName = "webrtc_audio_module_rec_thread"; - _ptrThreadRec = ThreadWrapper::CreateThread(RecThreadFunc, this, - threadName); + _ptrThreadRec = + PlatformThread::CreateThread(RecThreadFunc, this, threadName); if (!_ptrThreadRec->Start()) { WEBRTC_TRACE(kTraceCritical, kTraceAudioDevice, _id, @@ -216,8 +216,8 @@ int32_t AudioDeviceLinuxPulse::Init() // PLAYOUT threadName = "webrtc_audio_module_play_thread"; - _ptrThreadPlay = ThreadWrapper::CreateThread(PlayThreadFunc, this, - threadName); + _ptrThreadPlay = + PlatformThread::CreateThread(PlayThreadFunc, this, threadName); if (!_ptrThreadPlay->Start()) { WEBRTC_TRACE(kTraceCritical, kTraceAudioDevice, _id, @@ -246,7 +246,7 @@ int32_t AudioDeviceLinuxPulse::Terminate() // RECORDING if (_ptrThreadRec) { - ThreadWrapper* tmpThread = _ptrThreadRec.release(); + PlatformThread* tmpThread = _ptrThreadRec.release(); _timeEventRec.Set(); tmpThread->Stop(); @@ -256,7 +256,7 @@ int32_t AudioDeviceLinuxPulse::Terminate() // PLAYOUT if (_ptrThreadPlay) { - ThreadWrapper* tmpThread = _ptrThreadPlay.release(); + PlatformThread* tmpThread = _ptrThreadPlay.release(); _timeEventPlay.Set(); tmpThread->Stop(); diff --git a/webrtc/modules/audio_device/linux/audio_device_pulse_linux.h b/webrtc/modules/audio_device/linux/audio_device_pulse_linux.h index 718331188d..263d42da3a 100644 --- a/webrtc/modules/audio_device/linux/audio_device_pulse_linux.h +++ b/webrtc/modules/audio_device/linux/audio_device_pulse_linux.h @@ -11,11 +11,11 @@ #ifndef WEBRTC_AUDIO_DEVICE_AUDIO_DEVICE_PULSE_LINUX_H #define WEBRTC_AUDIO_DEVICE_AUDIO_DEVICE_PULSE_LINUX_H +#include "webrtc/base/platform_thread.h" +#include "webrtc/base/thread_checker.h" #include "webrtc/modules/audio_device/audio_device_generic.h" #include "webrtc/modules/audio_device/linux/audio_mixer_manager_pulse_linux.h" #include "webrtc/system_wrappers/include/critical_section_wrapper.h" -#include "webrtc/system_wrappers/include/thread_wrapper.h" -#include "webrtc/base/thread_checker.h" #include #include @@ -284,8 +284,8 @@ private: EventWrapper& _recStartEvent; EventWrapper& _playStartEvent; - rtc::scoped_ptr _ptrThreadPlay; - rtc::scoped_ptr _ptrThreadRec; + rtc::scoped_ptr _ptrThreadPlay; + rtc::scoped_ptr _ptrThreadRec; int32_t _id; AudioMixerManagerLinuxPulse _mixerManager; diff --git a/webrtc/modules/audio_device/mac/audio_device_mac.cc b/webrtc/modules/audio_device/mac/audio_device_mac.cc index db98675bf6..14e6bbdfbb 100644 --- a/webrtc/modules/audio_device/mac/audio_device_mac.cc +++ b/webrtc/modules/audio_device/mac/audio_device_mac.cc @@ -10,11 +10,11 @@ #include "webrtc/base/arraysize.h" #include "webrtc/base/checks.h" +#include "webrtc/base/platform_thread.h" #include "webrtc/modules/audio_device/audio_device_config.h" #include "webrtc/modules/audio_device/mac/audio_device_mac.h" #include "webrtc/modules/audio_device/mac/portaudio/pa_ringbuffer.h" #include "webrtc/system_wrappers/include/event_wrapper.h" -#include "webrtc/system_wrappers/include/thread_wrapper.h" #include "webrtc/system_wrappers/include/trace.h" #include @@ -1666,7 +1666,7 @@ int32_t AudioDeviceMac::StartRecording() RTC_DCHECK(!capture_worker_thread_.get()); capture_worker_thread_ = - ThreadWrapper::CreateThread(RunCapture, this, "CaptureWorkerThread"); + PlatformThread::CreateThread(RunCapture, this, "CaptureWorkerThread"); RTC_DCHECK(capture_worker_thread_.get()); capture_worker_thread_->Start(); capture_worker_thread_->SetPriority(kRealtimePriority); @@ -1821,7 +1821,7 @@ int32_t AudioDeviceMac::StartPlayout() RTC_DCHECK(!render_worker_thread_.get()); render_worker_thread_ = - ThreadWrapper::CreateThread(RunRender, this, "RenderWorkerThread"); + PlatformThread::CreateThread(RunRender, this, "RenderWorkerThread"); render_worker_thread_->Start(); render_worker_thread_->SetPriority(kRealtimePriority); diff --git a/webrtc/modules/audio_device/mac/audio_device_mac.h b/webrtc/modules/audio_device/mac/audio_device_mac.h index f2b66b4d06..d908fc5752 100644 --- a/webrtc/modules/audio_device/mac/audio_device_mac.h +++ b/webrtc/modules/audio_device/mac/audio_device_mac.h @@ -26,7 +26,7 @@ struct PaUtilRingBuffer; namespace webrtc { class EventWrapper; -class ThreadWrapper; +class PlatformThread; const uint32_t N_REC_SAMPLES_PER_SEC = 48000; const uint32_t N_PLAY_SAMPLES_PER_SEC = 48000; @@ -283,10 +283,10 @@ private: EventWrapper& _stopEvent; // Only valid/running between calls to StartRecording and StopRecording. - rtc::scoped_ptr capture_worker_thread_; + rtc::scoped_ptr capture_worker_thread_; // Only valid/running between calls to StartPlayout and StopPlayout. - rtc::scoped_ptr render_worker_thread_; + rtc::scoped_ptr render_worker_thread_; int32_t _id; diff --git a/webrtc/modules/audio_device/test/func_test_manager.cc b/webrtc/modules/audio_device/test/func_test_manager.cc index 0ebfc8395f..241c072d82 100644 --- a/webrtc/modules/audio_device/test/func_test_manager.cc +++ b/webrtc/modules/audio_device/test/func_test_manager.cc @@ -686,7 +686,7 @@ int32_t FuncTestManager::Close() _audioDevice = NULL; } - // return the ThreadWrapper (singleton) + // return the PlatformThread (singleton) Trace::ReturnTrace(); // PRINT_TEST_RESULTS; diff --git a/webrtc/modules/audio_device/win/audio_device_wave_win.cc b/webrtc/modules/audio_device/win/audio_device_wave_win.cc index 96bee7425a..dec5401503 100644 --- a/webrtc/modules/audio_device/win/audio_device_wave_win.cc +++ b/webrtc/modules/audio_device/win/audio_device_wave_win.cc @@ -228,7 +228,7 @@ int32_t AudioDeviceWindowsWave::Init() } const char* threadName = "webrtc_audio_module_thread"; - _ptrThread = ThreadWrapper::CreateThread(ThreadFunc, this, threadName); + _ptrThread = PlatformThread::CreateThread(ThreadFunc, this, threadName); if (!_ptrThread->Start()) { WEBRTC_TRACE(kTraceCritical, kTraceAudioDevice, _id, @@ -250,12 +250,8 @@ int32_t AudioDeviceWindowsWave::Init() WEBRTC_TRACE(kTraceInfo, kTraceAudioDevice, _id, "periodic timer (dT=%d) is now active", TIMER_PERIOD_MS); - _hGetCaptureVolumeThread = CreateThread(NULL, - 0, - GetCaptureVolumeThread, - this, - 0, - NULL); + _hGetCaptureVolumeThread = + CreateThread(NULL, 0, GetCaptureVolumeThread, this, 0, NULL); if (_hGetCaptureVolumeThread == NULL) { WEBRTC_TRACE(kTraceError, kTraceAudioDevice, _id, @@ -265,12 +261,8 @@ int32_t AudioDeviceWindowsWave::Init() SetThreadPriority(_hGetCaptureVolumeThread, THREAD_PRIORITY_NORMAL); - _hSetCaptureVolumeThread = CreateThread(NULL, - 0, - SetCaptureVolumeThread, - this, - 0, - NULL); + _hSetCaptureVolumeThread = + CreateThread(NULL, 0, SetCaptureVolumeThread, this, 0, NULL); if (_hSetCaptureVolumeThread == NULL) { WEBRTC_TRACE(kTraceError, kTraceAudioDevice, _id, @@ -303,7 +295,7 @@ int32_t AudioDeviceWindowsWave::Terminate() if (_ptrThread) { - ThreadWrapper* tmpThread = _ptrThread.release(); + PlatformThread* tmpThread = _ptrThread.release(); _critSect.Leave(); _timeEvent.Set(); diff --git a/webrtc/modules/audio_device/win/audio_device_wave_win.h b/webrtc/modules/audio_device/win/audio_device_wave_win.h index c99185c3ab..6e290145ed 100644 --- a/webrtc/modules/audio_device/win/audio_device_wave_win.h +++ b/webrtc/modules/audio_device/win/audio_device_wave_win.h @@ -11,9 +11,9 @@ #ifndef WEBRTC_AUDIO_DEVICE_AUDIO_DEVICE_WAVE_WIN_H #define WEBRTC_AUDIO_DEVICE_AUDIO_DEVICE_WAVE_WIN_H +#include "webrtc/base/platform_thread.h" #include "webrtc/modules/audio_device/audio_device_generic.h" #include "webrtc/modules/audio_device/win/audio_mixer_manager_win.h" -#include "webrtc/system_wrappers/include/thread_wrapper.h" #pragma comment( lib, "winmm.lib" ) @@ -222,7 +222,7 @@ private: HANDLE _hShutdownSetVolumeEvent; HANDLE _hSetCaptureVolumeEvent; - rtc::scoped_ptr _ptrThread; + rtc::scoped_ptr _ptrThread; CriticalSectionWrapper& _critSectCb; diff --git a/webrtc/modules/audio_processing/audio_processing_impl_locking_unittest.cc b/webrtc/modules/audio_processing/audio_processing_impl_locking_unittest.cc index d1dabee636..bccccf49ef 100644 --- a/webrtc/modules/audio_processing/audio_processing_impl_locking_unittest.cc +++ b/webrtc/modules/audio_processing/audio_processing_impl_locking_unittest.cc @@ -16,12 +16,12 @@ #include "testing/gtest/include/gtest/gtest.h" #include "webrtc/base/array_view.h" #include "webrtc/base/criticalsection.h" +#include "webrtc/base/platform_thread.h" #include "webrtc/config.h" #include "webrtc/modules/audio_processing/test/test_utils.h" #include "webrtc/modules/include/module_common_types.h" #include "webrtc/system_wrappers/include/event_wrapper.h" #include "webrtc/system_wrappers/include/sleep.h" -#include "webrtc/system_wrappers/include/thread_wrapper.h" #include "webrtc/test/random.h" namespace webrtc { @@ -456,9 +456,9 @@ class AudioProcessingImplLockTest const rtc::scoped_ptr test_complete_; // Thread related variables. - rtc::scoped_ptr render_thread_; - rtc::scoped_ptr capture_thread_; - rtc::scoped_ptr stats_thread_; + rtc::scoped_ptr render_thread_; + rtc::scoped_ptr capture_thread_; + rtc::scoped_ptr stats_thread_; mutable test::Random rand_gen_; rtc::scoped_ptr apm_; @@ -472,14 +472,15 @@ class AudioProcessingImplLockTest AudioProcessingImplLockTest::AudioProcessingImplLockTest() : test_complete_(EventWrapper::Create()), - render_thread_(ThreadWrapper::CreateThread(RenderProcessorThreadFunc, - this, - "render")), - capture_thread_(ThreadWrapper::CreateThread(CaptureProcessorThreadFunc, + render_thread_(PlatformThread::CreateThread(RenderProcessorThreadFunc, this, - "capture")), - stats_thread_( - ThreadWrapper::CreateThread(StatsProcessorThreadFunc, this, "stats")), + "render")), + capture_thread_(PlatformThread::CreateThread(CaptureProcessorThreadFunc, + this, + "capture")), + stats_thread_(PlatformThread::CreateThread(StatsProcessorThreadFunc, + this, + "stats")), rand_gen_(42U), apm_(AudioProcessingImpl::Create()), render_thread_state_(kMaxFrameSize, diff --git a/webrtc/modules/rtp_rtcp/test/BWEStandAlone/MatlabPlot.cc b/webrtc/modules/rtp_rtcp/test/BWEStandAlone/MatlabPlot.cc index fe54d67ee7..72f75f3454 100644 --- a/webrtc/modules/rtp_rtcp/test/BWEStandAlone/MatlabPlot.cc +++ b/webrtc/modules/rtp_rtcp/test/BWEStandAlone/MatlabPlot.cc @@ -895,8 +895,8 @@ _numPlots(0) { _eventPtr = EventWrapper::Create(); - _plotThread = ThreadWrapper::CreateThread(MatlabEngine::PlotThread, this, - kLowPriority, "MatlabPlot"); + _plotThread = PlatformThread::CreateThread(MatlabEngine::PlotThread, this, + kLowPriority, "MatlabPlot"); _running = true; _plotThread->Start(); } diff --git a/webrtc/modules/rtp_rtcp/test/BWEStandAlone/MatlabPlot.h b/webrtc/modules/rtp_rtcp/test/BWEStandAlone/MatlabPlot.h index 3ed89f8f91..549e5cc021 100644 --- a/webrtc/modules/rtp_rtcp/test/BWEStandAlone/MatlabPlot.h +++ b/webrtc/modules/rtp_rtcp/test/BWEStandAlone/MatlabPlot.h @@ -15,8 +15,8 @@ #include #include +#include "webrtc/base/platform_thread.h" #include "webrtc/typedefs.h" -#include "webrtc/system_wrappers/include/thread_wrapper.h" namespace webrtc { class CriticalSectionWrapper; @@ -160,7 +160,7 @@ private: std::vector _plots; webrtc::CriticalSectionWrapper *_critSect; webrtc::EventWrapper *_eventPtr; - rtc::scoped_ptr _plotThread; + rtc::scoped_ptr _plotThread; bool _running; int _numPlots; }; diff --git a/webrtc/modules/rtp_rtcp/test/BWEStandAlone/TestLoadGenerator.cc b/webrtc/modules/rtp_rtcp/test/BWEStandAlone/TestLoadGenerator.cc index 0e3e87976c..236ceae937 100644 --- a/webrtc/modules/rtp_rtcp/test/BWEStandAlone/TestLoadGenerator.cc +++ b/webrtc/modules/rtp_rtcp/test/BWEStandAlone/TestLoadGenerator.cc @@ -76,8 +76,8 @@ int32_t TestLoadGenerator::Start (const char *threadName) _eventPtr = EventWrapper::Create(); - _genThread = ThreadWrapper::CreateThread(SenderThreadFunction, this, - threadName); + _genThread = + PlatformThread::CreateThread(SenderThreadFunction, this, threadName); _running = true; _genThread->Start(); diff --git a/webrtc/modules/rtp_rtcp/test/BWEStandAlone/TestLoadGenerator.h b/webrtc/modules/rtp_rtcp/test/BWEStandAlone/TestLoadGenerator.h index 59742b2329..23f61b2158 100644 --- a/webrtc/modules/rtp_rtcp/test/BWEStandAlone/TestLoadGenerator.h +++ b/webrtc/modules/rtp_rtcp/test/BWEStandAlone/TestLoadGenerator.h @@ -13,8 +13,8 @@ #include +#include "webrtc/base/platform_thread.h" #include "webrtc/modules/include/module_common_types.h" -#include "webrtc/system_wrappers/include/thread_wrapper.h" #include "webrtc/typedefs.h" class TestSenderReceiver; @@ -44,7 +44,7 @@ protected: webrtc::CriticalSectionWrapper* _critSect; webrtc::EventWrapper *_eventPtr; - rtc::scoped_ptr _genThread; + rtc::scoped_ptr _genThread; int32_t _bitrateKbps; TestSenderReceiver *_sender; bool _running; diff --git a/webrtc/modules/rtp_rtcp/test/BWEStandAlone/TestSenderReceiver.cc b/webrtc/modules/rtp_rtcp/test/BWEStandAlone/TestSenderReceiver.cc index c1d91cdbc3..99a41eec39 100644 --- a/webrtc/modules/rtp_rtcp/test/BWEStandAlone/TestSenderReceiver.cc +++ b/webrtc/modules/rtp_rtcp/test/BWEStandAlone/TestSenderReceiver.cc @@ -162,8 +162,8 @@ int32_t TestSenderReceiver::Start() exit(1); } - _procThread = ThreadWrapper::CreateThread(ProcThreadFunction, this, - "TestSenderReceiver"); + _procThread = PlatformThread::CreateThread(ProcThreadFunction, this, + "TestSenderReceiver"); _running = true; diff --git a/webrtc/modules/rtp_rtcp/test/BWEStandAlone/TestSenderReceiver.h b/webrtc/modules/rtp_rtcp/test/BWEStandAlone/TestSenderReceiver.h index 02fbe0a936..77b02d043d 100644 --- a/webrtc/modules/rtp_rtcp/test/BWEStandAlone/TestSenderReceiver.h +++ b/webrtc/modules/rtp_rtcp/test/BWEStandAlone/TestSenderReceiver.h @@ -11,9 +11,9 @@ #ifndef WEBRTC_MODULES_RTP_RTCP_TEST_BWESTANDALONE_TESTSENDERRECEIVER_H_ #define WEBRTC_MODULES_RTP_RTCP_TEST_BWESTANDALONE_TESTSENDERRECEIVER_H_ +#include "webrtc/base/platform_thread.h" #include "webrtc/modules/rtp_rtcp/include/rtp_rtcp.h" #include "webrtc/modules/rtp_rtcp/include/rtp_rtcp_defines.h" -#include "webrtc/system_wrappers/include/thread_wrapper.h" #include "webrtc/test/channel_transport/udp_transport.h" #include "webrtc/typedefs.h" @@ -138,7 +138,7 @@ private: UdpTransport* _transport; webrtc::CriticalSectionWrapper* _critSect; webrtc::EventWrapper *_eventPtr; - rtc::scoped_ptr _procThread; + rtc::scoped_ptr _procThread; bool _running; int8_t _payloadType; TestLoadGenerator* _loadGenerator; diff --git a/webrtc/modules/utility/source/file_recorder_impl.h b/webrtc/modules/utility/source/file_recorder_impl.h index e3f06c455e..697d759375 100644 --- a/webrtc/modules/utility/source/file_recorder_impl.h +++ b/webrtc/modules/utility/source/file_recorder_impl.h @@ -17,6 +17,7 @@ #include +#include "webrtc/base/platform_thread.h" #include "webrtc/common_audio/resampler/include/resampler.h" #include "webrtc/common_types.h" #include "webrtc/engine_configurations.h" @@ -26,7 +27,6 @@ #include "webrtc/modules/utility/include/file_recorder.h" #include "webrtc/modules/utility/source/coder.h" #include "webrtc/system_wrappers/include/event_wrapper.h" -#include "webrtc/system_wrappers/include/thread_wrapper.h" #include "webrtc/system_wrappers/include/tick_util.h" #include "webrtc/typedefs.h" diff --git a/webrtc/modules/utility/source/process_thread_impl.cc b/webrtc/modules/utility/source/process_thread_impl.cc index 9c739de8fc..63e77d9f55 100644 --- a/webrtc/modules/utility/source/process_thread_impl.cc +++ b/webrtc/modules/utility/source/process_thread_impl.cc @@ -76,8 +76,8 @@ void ProcessThreadImpl::Start() { m.module->ProcessThreadAttached(this); } - thread_ = ThreadWrapper::CreateThread(&ProcessThreadImpl::Run, this, - thread_name_); + thread_ = + PlatformThread::CreateThread(&ProcessThreadImpl::Run, this, thread_name_); RTC_CHECK(thread_->Start()); } diff --git a/webrtc/modules/utility/source/process_thread_impl.h b/webrtc/modules/utility/source/process_thread_impl.h index 0a956654f6..8f58932f25 100644 --- a/webrtc/modules/utility/source/process_thread_impl.h +++ b/webrtc/modules/utility/source/process_thread_impl.h @@ -15,10 +15,10 @@ #include #include "webrtc/base/criticalsection.h" +#include "webrtc/base/platform_thread.h" #include "webrtc/base/thread_checker.h" #include "webrtc/modules/utility/include/process_thread.h" #include "webrtc/system_wrappers/include/event_wrapper.h" -#include "webrtc/system_wrappers/include/thread_wrapper.h" #include "webrtc/typedefs.h" namespace webrtc { @@ -70,7 +70,7 @@ class ProcessThreadImpl : public ProcessThread { rtc::ThreadChecker thread_checker_; const rtc::scoped_ptr wake_up_; - rtc::scoped_ptr thread_; + rtc::scoped_ptr thread_; ModuleList modules_; // TODO(tommi): Support delayed tasks. diff --git a/webrtc/modules/video_capture/linux/video_capture_linux.cc b/webrtc/modules/video_capture/linux/video_capture_linux.cc index fe99c7136f..b8e3f62056 100644 --- a/webrtc/modules/video_capture/linux/video_capture_linux.cc +++ b/webrtc/modules/video_capture/linux/video_capture_linux.cc @@ -280,7 +280,7 @@ int32_t VideoCaptureModuleV4L2::StartCapture( //start capture thread; if (!_captureThread) { - _captureThread = ThreadWrapper::CreateThread( + _captureThread = PlatformThread::CreateThread( VideoCaptureModuleV4L2::CaptureThread, this, "CaptureThread"); _captureThread->Start(); _captureThread->SetPriority(kHighPriority); diff --git a/webrtc/modules/video_capture/linux/video_capture_linux.h b/webrtc/modules/video_capture/linux/video_capture_linux.h index 996f8e10ca..f791607796 100644 --- a/webrtc/modules/video_capture/linux/video_capture_linux.h +++ b/webrtc/modules/video_capture/linux/video_capture_linux.h @@ -11,9 +11,9 @@ #ifndef WEBRTC_MODULES_VIDEO_CAPTURE_MAIN_SOURCE_LINUX_VIDEO_CAPTURE_LINUX_H_ #define WEBRTC_MODULES_VIDEO_CAPTURE_MAIN_SOURCE_LINUX_VIDEO_CAPTURE_LINUX_H_ +#include "webrtc/base/platform_thread.h" #include "webrtc/common_types.h" #include "webrtc/modules/video_capture/video_capture_impl.h" -#include "webrtc/system_wrappers/include/thread_wrapper.h" namespace webrtc { @@ -39,7 +39,7 @@ private: bool AllocateVideoBuffers(); bool DeAllocateVideoBuffers(); - rtc::scoped_ptr _captureThread; + rtc::scoped_ptr _captureThread; CriticalSectionWrapper* _captureCritSect; int32_t _deviceId; diff --git a/webrtc/modules/video_render/android/video_render_android_impl.cc b/webrtc/modules/video_render/android/video_render_android_impl.cc index c647501963..63386e078c 100644 --- a/webrtc/modules/video_render/android/video_render_android_impl.cc +++ b/webrtc/modules/video_render/android/video_render_android_impl.cc @@ -141,8 +141,8 @@ int32_t VideoRenderAndroid::StartRender() { return 0; } - _javaRenderThread = ThreadWrapper::CreateThread(JavaRenderThreadFun, this, - "AndroidRenderThread"); + _javaRenderThread = PlatformThread::CreateThread(JavaRenderThreadFun, this, + "AndroidRenderThread"); if (_javaRenderThread->Start()) WEBRTC_TRACE(kTraceInfo, kTraceVideoRenderer, _id, diff --git a/webrtc/modules/video_render/android/video_render_android_impl.h b/webrtc/modules/video_render/android/video_render_android_impl.h index 34950db7d1..c038980922 100644 --- a/webrtc/modules/video_render/android/video_render_android_impl.h +++ b/webrtc/modules/video_render/android/video_render_android_impl.h @@ -15,8 +15,8 @@ #include +#include "webrtc/base/platform_thread.h" #include "webrtc/modules/video_render/i_video_render.h" -#include "webrtc/system_wrappers/include/thread_wrapper.h" namespace webrtc { @@ -144,7 +144,7 @@ class VideoRenderAndroid: IVideoRender { EventWrapper& _javaRenderEvent; int64_t _lastJavaRenderEvent; JNIEnv* _javaRenderJniEnv; // JNIEnv for the java render thread. - rtc::scoped_ptr _javaRenderThread; + rtc::scoped_ptr _javaRenderThread; }; } // namespace webrtc diff --git a/webrtc/modules/video_render/ios/video_render_ios_gles20.h b/webrtc/modules/video_render/ios/video_render_ios_gles20.h index b6da12aab8..51a0137f6b 100644 --- a/webrtc/modules/video_render/ios/video_render_ios_gles20.h +++ b/webrtc/modules/video_render/ios/video_render_ios_gles20.h @@ -14,10 +14,10 @@ #include #include +#include "webrtc/base/platform_thread.h" #include "webrtc/base/scoped_ptr.h" #include "webrtc/modules/video_render/ios/video_render_ios_channel.h" #include "webrtc/modules/video_render/ios/video_render_ios_view.h" -#include "webrtc/system_wrappers/include/thread_wrapper.h" namespace webrtc { @@ -64,7 +64,7 @@ class VideoRenderIosGles20 { private: rtc::scoped_ptr gles_crit_sec_; EventTimerWrapper* screen_update_event_; - rtc::scoped_ptr screen_update_thread_; + rtc::scoped_ptr screen_update_thread_; VideoRenderIosView* view_; Rect window_rect_; diff --git a/webrtc/modules/video_render/ios/video_render_ios_gles20.mm b/webrtc/modules/video_render/ios/video_render_ios_gles20.mm index 3a276d6030..0b4cac1986 100644 --- a/webrtc/modules/video_render/ios/video_render_ios_gles20.mm +++ b/webrtc/modules/video_render/ios/video_render_ios_gles20.mm @@ -32,7 +32,7 @@ VideoRenderIosGles20::VideoRenderIosGles20(VideoRenderIosView* view, z_order_to_channel_(), gles_context_([view context]), is_rendering_(true) { - screen_update_thread_ = ThreadWrapper::CreateThread( + screen_update_thread_ = PlatformThread::CreateThread( ScreenUpdateThreadProc, this, "ScreenUpdateGles20"); screen_update_event_ = EventTimerWrapper::Create(); GetWindowRect(window_rect_); @@ -40,7 +40,7 @@ VideoRenderIosGles20::VideoRenderIosGles20(VideoRenderIosView* view, VideoRenderIosGles20::~VideoRenderIosGles20() { // Signal event to exit thread, then delete it - ThreadWrapper* thread_wrapper = screen_update_thread_.release(); + PlatformThread* thread_wrapper = screen_update_thread_.release(); if (thread_wrapper) { screen_update_event_->Set(); diff --git a/webrtc/modules/video_render/mac/video_render_agl.cc b/webrtc/modules/video_render/mac/video_render_agl.cc index dc157d597b..32fa60739c 100644 --- a/webrtc/modules/video_render/mac/video_render_agl.cc +++ b/webrtc/modules/video_render/mac/video_render_agl.cc @@ -395,8 +395,8 @@ _renderingIsPaused( false), { //WEBRTC_TRACE(kTraceInfo, kTraceVideoRenderer, _id, "%s"); - _screenUpdateThread = ThreadWrapper::CreateThread( - ScreenUpdateThreadProc, this, "ScreenUpdate"); + _screenUpdateThread = PlatformThread::CreateThread(ScreenUpdateThreadProc, + this, "ScreenUpdate"); _screenUpdateEvent = EventWrapper::Create(); if(!IsValidWindowPtr(_windowRef)) @@ -512,7 +512,7 @@ _renderingIsPaused( false), //WEBRTC_TRACE(kTraceDebug, "%s:%d Constructor", __FUNCTION__, __LINE__); // _renderCritSec = CriticalSectionWrapper::CreateCriticalSection(); - _screenUpdateThread = ThreadWrapper::CreateThread( + _screenUpdateThread = PlatformThread::CreateThread( ScreenUpdateThreadProc, this, "ScreenUpdateThread"); _screenUpdateEvent = EventWrapper::Create(); @@ -677,7 +677,7 @@ VideoRenderAGL::~VideoRenderAGL() #endif // Signal event to exit thread, then delete it - ThreadWrapper* tmpPtr = _screenUpdateThread.release(); + PlatformThread* tmpPtr = _screenUpdateThread.release(); if (tmpPtr) { @@ -856,7 +856,7 @@ int VideoRenderAGL::DeleteAGLChannel(int channel) int VideoRenderAGL::StopThread() { CriticalSectionScoped cs(&_renderCritSec); - ThreadWrapper* tmpPtr = _screenUpdateThread.release(); + PlatformThread* tmpPtr = _screenUpdateThread.release(); if (tmpPtr) { @@ -1891,8 +1891,8 @@ int32_t VideoRenderAGL::StartRender() return 0; } - _screenUpdateThread = ThreadWrapper::CreateThread(ScreenUpdateThreadProc, - this, "ScreenUpdate"); + _screenUpdateThread = PlatformThread::CreateThread(ScreenUpdateThreadProc, + this, "ScreenUpdate"); _screenUpdateEvent = EventWrapper::Create(); if (!_screenUpdateThread) diff --git a/webrtc/modules/video_render/mac/video_render_agl.h b/webrtc/modules/video_render/mac/video_render_agl.h index 11e9c3ba86..0508a3f513 100644 --- a/webrtc/modules/video_render/mac/video_render_agl.h +++ b/webrtc/modules/video_render/mac/video_render_agl.h @@ -15,8 +15,8 @@ #ifndef WEBRTC_MODULES_VIDEO_RENDER_MAIN_SOURCE_MAC_VIDEO_RENDER_AGL_H_ #define WEBRTC_MODULES_VIDEO_RENDER_MAIN_SOURCE_MAC_VIDEO_RENDER_AGL_H_ +#include "webrtc/base/platform_thread.h" #include "webrtc/modules/video_render/video_render_defines.h" -#include "webrtc/system_wrappers/include/thread_wrapper.h" #define NEW_HIVIEW_PARENT_EVENT_HANDLER 1 #define NEW_HIVIEW_EVENT_HANDLER 1 @@ -142,7 +142,7 @@ class VideoRenderAGL { bool _fullScreen; int _id; webrtc::CriticalSectionWrapper& _renderCritSec; - rtc::scoped_ptr _screenUpdateThread; + rtc::scoped_ptr _screenUpdateThread; webrtc::EventWrapper* _screenUpdateEvent; bool _isHIViewRef; AGLContext _aglContext; diff --git a/webrtc/modules/video_render/mac/video_render_nsopengl.h b/webrtc/modules/video_render/mac/video_render_nsopengl.h index 8bc769a060..5993c088a7 100644 --- a/webrtc/modules/video_render/mac/video_render_nsopengl.h +++ b/webrtc/modules/video_render/mac/video_render_nsopengl.h @@ -32,7 +32,7 @@ class Trace; namespace webrtc { class EventTimerWrapper; -class ThreadWrapper; +class PlatformThread; class VideoRenderNSOpenGL; class CriticalSectionWrapper; @@ -166,7 +166,7 @@ private: // variables bool _fullScreen; int _id; CriticalSectionWrapper& _nsglContextCritSec; - rtc::scoped_ptr _screenUpdateThread; + rtc::scoped_ptr _screenUpdateThread; EventTimerWrapper* _screenUpdateEvent; NSOpenGLContext* _nsglContext; NSOpenGLContext* _nsglFullScreenContext; diff --git a/webrtc/modules/video_render/mac/video_render_nsopengl.mm b/webrtc/modules/video_render/mac/video_render_nsopengl.mm index b5150eb668..745709581e 100644 --- a/webrtc/modules/video_render/mac/video_render_nsopengl.mm +++ b/webrtc/modules/video_render/mac/video_render_nsopengl.mm @@ -11,11 +11,11 @@ #include "webrtc/engine_configurations.h" #if defined(COCOA_RENDERING) +#include "webrtc/base/platform_thread.h" #include "webrtc/common_video/libyuv/include/webrtc_libyuv.h" #include "webrtc/modules/video_render/mac/video_render_nsopengl.h" #include "webrtc/system_wrappers/include/critical_section_wrapper.h" #include "webrtc/system_wrappers/include/event_wrapper.h" -#include "webrtc/system_wrappers/include/thread_wrapper.h" #include "webrtc/system_wrappers/include/trace.h" namespace webrtc { @@ -378,8 +378,8 @@ _renderingIsPaused (FALSE), _windowRefSuperView(NULL), _windowRefSuperViewFrame(NSMakeRect(0,0,0,0)) { - _screenUpdateThread = ThreadWrapper::CreateThread(ScreenUpdateThreadProc, - this, "ScreenUpdateNSOpenGL"); + _screenUpdateThread = PlatformThread::CreateThread( + ScreenUpdateThreadProc, this, "ScreenUpdateNSOpenGL"); } int VideoRenderNSOpenGL::ChangeWindow(CocoaRenderView* newWindowRef) @@ -657,7 +657,7 @@ VideoRenderNSOpenGL::~VideoRenderNSOpenGL() } // Signal event to exit thread, then delete it - ThreadWrapper* tmpPtr = _screenUpdateThread.release(); + PlatformThread* tmpPtr = _screenUpdateThread.release(); if (tmpPtr) { @@ -864,7 +864,7 @@ int32_t VideoRenderNSOpenGL::GetChannelProperties(const uint16_t streamId, int VideoRenderNSOpenGL::StopThread() { - ThreadWrapper* tmpPtr = _screenUpdateThread.release(); + PlatformThread* tmpPtr = _screenUpdateThread.release(); WEBRTC_TRACE(kTraceInfo, kTraceVideoRenderer, _id, "%s Stopping thread ", __FUNCTION__, tmpPtr); diff --git a/webrtc/modules/video_render/windows/video_render_direct3d9.cc b/webrtc/modules/video_render/windows/video_render_direct3d9.cc index 24dd0efddb..5458c28667 100644 --- a/webrtc/modules/video_render/windows/video_render_direct3d9.cc +++ b/webrtc/modules/video_render/windows/video_render_direct3d9.cc @@ -294,7 +294,7 @@ VideoRenderDirect3D9::VideoRenderDirect3D9(Trace* trace, _totalMemory(0), _availableMemory(0) { - _screenUpdateThread = ThreadWrapper::CreateThread( + _screenUpdateThread = PlatformThread::CreateThread( ScreenUpdateThreadProc, this, "ScreenUpdateThread"); _screenUpdateEvent = EventTimerWrapper::Create(); SetRect(&_originalHwndRect, 0, 0, 0, 0); @@ -305,7 +305,7 @@ VideoRenderDirect3D9::~VideoRenderDirect3D9() //NOTE: we should not enter CriticalSection in here! // Signal event to exit thread, then delete it - ThreadWrapper* tmpPtr = _screenUpdateThread.release(); + PlatformThread* tmpPtr = _screenUpdateThread.release(); if (tmpPtr) { _screenUpdateEvent->Set(); diff --git a/webrtc/modules/video_render/windows/video_render_direct3d9.h b/webrtc/modules/video_render/windows/video_render_direct3d9.h index 8b8509ed4e..c98f08f488 100644 --- a/webrtc/modules/video_render/windows/video_render_direct3d9.h +++ b/webrtc/modules/video_render/windows/video_render_direct3d9.h @@ -19,8 +19,8 @@ #include // Added +#include "webrtc/base/platform_thread.h" #include "webrtc/modules/video_render/video_render_defines.h" -#include "webrtc/system_wrappers/include/thread_wrapper.h" #pragma comment(lib, "d3d9.lib") // located in DirectX SDK @@ -203,7 +203,7 @@ private: CriticalSectionWrapper& _refD3DCritsect; Trace* _trace; - rtc::scoped_ptr _screenUpdateThread; + rtc::scoped_ptr _screenUpdateThread; EventTimerWrapper* _screenUpdateEvent; HWND _hWnd; diff --git a/webrtc/system_wrappers/BUILD.gn b/webrtc/system_wrappers/BUILD.gn index d0447e9ca1..5e0e41e832 100644 --- a/webrtc/system_wrappers/BUILD.gn +++ b/webrtc/system_wrappers/BUILD.gn @@ -37,7 +37,6 @@ static_library("system_wrappers") { "include/static_instance.h", "include/stl_util.h", "include/stringize_macros.h", - "include/thread_wrapper.h", "include/tick_util.h", "include/timestamp_extrapolator.h", "include/trace.h", @@ -79,11 +78,6 @@ static_library("system_wrappers") { "source/rw_lock_win.h", "source/sleep.cc", "source/sort.cc", - "source/thread.cc", - "source/thread_posix.cc", - "source/thread_posix.h", - "source/thread_win.cc", - "source/thread_win.h", "source/tick_util.cc", "source/timestamp_extrapolator.cc", "source/trace_impl.cc", @@ -193,9 +187,9 @@ source_set("system_wrappers_default") { public_configs = [ "..:common_inherited_config" ] deps = [ - ":system_wrappers", ":field_trial_default", ":metrics_default", + ":system_wrappers", ] } diff --git a/webrtc/system_wrappers/include/data_log_impl.h b/webrtc/system_wrappers/include/data_log_impl.h index 1932a345b6..723cca31fb 100644 --- a/webrtc/system_wrappers/include/data_log_impl.h +++ b/webrtc/system_wrappers/include/data_log_impl.h @@ -22,8 +22,8 @@ #include #include +#include "webrtc/base/platform_thread.h" #include "webrtc/base/scoped_ptr.h" -#include "webrtc/system_wrappers/include/thread_wrapper.h" #include "webrtc/typedefs.h" namespace webrtc { @@ -146,7 +146,7 @@ class DataLogImpl { int counter_; TableMap tables_; EventWrapper* flush_event_; - rtc::scoped_ptr file_writer_thread_; + rtc::scoped_ptr file_writer_thread_; RWLockWrapper* tables_lock_; }; diff --git a/webrtc/system_wrappers/include/thread_wrapper.h b/webrtc/system_wrappers/include/thread_wrapper.h deleted file mode 100644 index dbd548dfd9..0000000000 --- a/webrtc/system_wrappers/include/thread_wrapper.h +++ /dev/null @@ -1,89 +0,0 @@ -/* - * Copyright (c) 2011 The WebRTC project authors. All Rights Reserved. - * - * Use of this source code is governed by a BSD-style license - * that can be found in the LICENSE file in the root of the source - * tree. An additional intellectual property rights grant can be found - * in the file PATENTS. All contributing project authors may - * be found in the AUTHORS file in the root of the source tree. - */ - -// System independant wrapper for spawning threads -// Note: the spawned thread will loop over the callback function until stopped. -// Note: The callback function is expected to return every 2 seconds or more -// often. - -#ifndef WEBRTC_SYSTEM_WRAPPERS_INCLUDE_THREAD_WRAPPER_H_ -#define WEBRTC_SYSTEM_WRAPPERS_INCLUDE_THREAD_WRAPPER_H_ - -#if defined(WEBRTC_WIN) -#include -#endif - -#include "webrtc/base/scoped_ptr.h" -#include "webrtc/common_types.h" -#include "webrtc/typedefs.h" - -namespace webrtc { - -// Callback function that the spawned thread will enter once spawned. -// A return value of false is interpreted as that the function has no -// more work to do and that the thread can be released. -typedef bool(*ThreadRunFunction)(void*); - -enum ThreadPriority { -#ifdef WEBRTC_WIN - kLowPriority = THREAD_PRIORITY_BELOW_NORMAL, - kNormalPriority = THREAD_PRIORITY_NORMAL, - kHighPriority = THREAD_PRIORITY_ABOVE_NORMAL, - kHighestPriority = THREAD_PRIORITY_HIGHEST, - kRealtimePriority = THREAD_PRIORITY_TIME_CRITICAL -#else - kLowPriority = 1, - kNormalPriority = 2, - kHighPriority = 3, - kHighestPriority = 4, - kRealtimePriority = 5 -#endif -}; - -// Represents a simple worker thread. The implementation must be assumed -// to be single threaded, meaning that all methods of the class, must be -// called from the same thread, including instantiation. -// TODO(tommi): There's no need for this to be a virtual interface since there's -// only ever a single implementation of it. -class ThreadWrapper { - public: - virtual ~ThreadWrapper() {} - - // Factory method. Constructor disabled. - // - // func Pointer to a, by user, specified callback function. - // obj Object associated with the thread. Passed in the callback - // function. - // prio Thread priority. May require root/admin rights. - // thread_name NULL terminated thread name, will be visable in the Windows - // debugger. - static rtc::scoped_ptr CreateThread(ThreadRunFunction func, - void* obj, const char* thread_name); - - // Tries to spawns a thread and returns true if that was successful. - // Additionally, it tries to set thread priority according to the priority - // from when CreateThread was called. However, failure to set priority will - // not result in a false return value. - virtual bool Start() = 0; - - // Stops the spawned thread and waits for it to be reclaimed with a timeout - // of two seconds. Will return false if the thread was not reclaimed. - // Multiple tries to Stop are allowed (e.g. to wait longer than 2 seconds). - // It's ok to call Stop() even if the spawned thread has been reclaimed. - virtual bool Stop() = 0; - - // Set the priority of the worker thread. Must be called when thread - // is running. - virtual bool SetPriority(ThreadPriority priority) = 0; -}; - -} // namespace webrtc - -#endif // WEBRTC_SYSTEM_WRAPPERS_INCLUDE_THREAD_WRAPPER_H_ diff --git a/webrtc/system_wrappers/source/condition_variable_unittest.cc b/webrtc/system_wrappers/source/condition_variable_unittest.cc index ed845cc21e..aad55ac611 100644 --- a/webrtc/system_wrappers/source/condition_variable_unittest.cc +++ b/webrtc/system_wrappers/source/condition_variable_unittest.cc @@ -11,9 +11,9 @@ #include "webrtc/system_wrappers/include/condition_variable_wrapper.h" #include "testing/gtest/include/gtest/gtest.h" +#include "webrtc/base/platform_thread.h" #include "webrtc/base/scoped_ptr.h" #include "webrtc/system_wrappers/include/critical_section_wrapper.h" -#include "webrtc/system_wrappers/include/thread_wrapper.h" #include "webrtc/system_wrappers/include/tick_util.h" #include "webrtc/system_wrappers/include/trace.h" @@ -147,8 +147,8 @@ class CondVarTest : public ::testing::Test { CondVarTest() {} virtual void SetUp() { - thread_ = ThreadWrapper::CreateThread(&WaitingRunFunction, - &baton_, "CondVarTest"); + thread_ = PlatformThread::CreateThread(&WaitingRunFunction, &baton_, + "CondVarTest"); ASSERT_TRUE(thread_->Start()); } @@ -167,7 +167,7 @@ class CondVarTest : public ::testing::Test { Baton baton_; private: - rtc::scoped_ptr thread_; + rtc::scoped_ptr thread_; }; // The SetUp and TearDown functions use condition variables. diff --git a/webrtc/system_wrappers/source/critical_section_unittest.cc b/webrtc/system_wrappers/source/critical_section_unittest.cc index 6848bdd06b..347cb55c91 100644 --- a/webrtc/system_wrappers/source/critical_section_unittest.cc +++ b/webrtc/system_wrappers/source/critical_section_unittest.cc @@ -12,7 +12,7 @@ #include "testing/gtest/include/gtest/gtest.h" #include "webrtc/system_wrappers/include/sleep.h" -#include "webrtc/system_wrappers/include/thread_wrapper.h" +#include "webrtc/base/platform_thread.h" #include "webrtc/system_wrappers/include/trace.h" namespace webrtc { @@ -78,7 +78,7 @@ TEST_F(CritSectTest, ThreadWakesOnce) NO_THREAD_SAFETY_ANALYSIS { CriticalSectionWrapper* crit_sect = CriticalSectionWrapper::CreateCriticalSection(); ProtectedCount count(crit_sect); - rtc::scoped_ptr thread = ThreadWrapper::CreateThread( + rtc::scoped_ptr thread = PlatformThread::CreateThread( &LockUnlockThenStopRunFunction, &count, "ThreadWakesOnce"); crit_sect->Enter(); ASSERT_TRUE(thread->Start()); @@ -105,7 +105,7 @@ TEST_F(CritSectTest, ThreadWakesTwice) NO_THREAD_SAFETY_ANALYSIS { CriticalSectionWrapper* crit_sect = CriticalSectionWrapper::CreateCriticalSection(); ProtectedCount count(crit_sect); - rtc::scoped_ptr thread = ThreadWrapper::CreateThread( + rtc::scoped_ptr thread = PlatformThread::CreateThread( &LockUnlockRunFunction, &count, "ThreadWakesTwice"); crit_sect->Enter(); // Make sure counter stays 0 until we wait for it. ASSERT_TRUE(thread->Start()); diff --git a/webrtc/system_wrappers/source/data_log.cc b/webrtc/system_wrappers/source/data_log.cc index dbc8ea1505..c25971d98a 100644 --- a/webrtc/system_wrappers/source/data_log.cc +++ b/webrtc/system_wrappers/source/data_log.cc @@ -348,8 +348,8 @@ int DataLogImpl::CreateLog() { } int DataLogImpl::Init() { - file_writer_thread_ = ThreadWrapper::CreateThread( - DataLogImpl::Run, instance_, "DataLog"); + file_writer_thread_ = + PlatformThread::CreateThread(DataLogImpl::Run, instance_, "DataLog"); bool success = file_writer_thread_->Start(); if (!success) return -1; diff --git a/webrtc/system_wrappers/source/event_timer_posix.cc b/webrtc/system_wrappers/source/event_timer_posix.cc index 99eebcb70a..ff26e76ec0 100644 --- a/webrtc/system_wrappers/source/event_timer_posix.cc +++ b/webrtc/system_wrappers/source/event_timer_posix.cc @@ -154,7 +154,7 @@ bool EventTimerPosix::StartTimer(bool periodic, unsigned long time) { // Start the timer thread timer_event_.reset(new EventTimerPosix()); const char* thread_name = "WebRtc_event_timer_thread"; - timer_thread_ = ThreadWrapper::CreateThread(Run, this, thread_name); + timer_thread_ = PlatformThread::CreateThread(Run, this, thread_name); periodic_ = periodic; time_ = time; bool started = timer_thread_->Start(); diff --git a/webrtc/system_wrappers/source/event_timer_posix.h b/webrtc/system_wrappers/source/event_timer_posix.h index 21c4ac702e..6e45b387f9 100644 --- a/webrtc/system_wrappers/source/event_timer_posix.h +++ b/webrtc/system_wrappers/source/event_timer_posix.h @@ -16,7 +16,7 @@ #include #include -#include "webrtc/system_wrappers/include/thread_wrapper.h" +#include "webrtc/base/platform_thread.h" namespace webrtc { @@ -46,7 +46,7 @@ class EventTimerPosix : public EventTimerWrapper { pthread_mutex_t mutex_; bool event_set_; - rtc::scoped_ptr timer_thread_; + rtc::scoped_ptr timer_thread_; rtc::scoped_ptr timer_event_; timespec created_at_; diff --git a/webrtc/system_wrappers/source/thread.cc b/webrtc/system_wrappers/source/thread.cc deleted file mode 100644 index 7da1e3d591..0000000000 --- a/webrtc/system_wrappers/source/thread.cc +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright (c) 2011 The WebRTC project authors. All Rights Reserved. - * - * Use of this source code is governed by a BSD-style license - * that can be found in the LICENSE file in the root of the source - * tree. An additional intellectual property rights grant can be found - * in the file PATENTS. All contributing project authors may - * be found in the AUTHORS file in the root of the source tree. - */ - -#include "webrtc/system_wrappers/include/thread_wrapper.h" - -#if defined(_WIN32) -#include "webrtc/system_wrappers/source/thread_win.h" -#else -#include "webrtc/system_wrappers/source/thread_posix.h" -#endif - -namespace webrtc { - -#if defined(_WIN32) -typedef ThreadWindows ThreadType; -#else -typedef ThreadPosix ThreadType; -#endif - -rtc::scoped_ptr ThreadWrapper::CreateThread( - ThreadRunFunction func, void* obj, const char* thread_name) { - return rtc::scoped_ptr( - new ThreadType(func, obj, thread_name)).Pass(); -} - -} // namespace webrtc diff --git a/webrtc/system_wrappers/source/thread_posix.cc b/webrtc/system_wrappers/source/thread_posix.cc deleted file mode 100644 index 952a3cd0f9..0000000000 --- a/webrtc/system_wrappers/source/thread_posix.cc +++ /dev/null @@ -1,161 +0,0 @@ -/* - * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved. - * - * Use of this source code is governed by a BSD-style license - * that can be found in the LICENSE file in the root of the source - * tree. An additional intellectual property rights grant can be found - * in the file PATENTS. All contributing project authors may - * be found in the AUTHORS file in the root of the source tree. - */ - -#include "webrtc/system_wrappers/source/thread_posix.h" - -#include - -#include -#include -#ifdef WEBRTC_LINUX -#include -#include -#include -#endif - -#include "webrtc/base/checks.h" -#include "webrtc/system_wrappers/include/critical_section_wrapper.h" -#include "webrtc/system_wrappers/include/event_wrapper.h" -#include "webrtc/system_wrappers/include/sleep.h" -#include "webrtc/system_wrappers/include/trace.h" - -namespace webrtc { -namespace { -struct ThreadAttributes { - ThreadAttributes() { pthread_attr_init(&attr); } - ~ThreadAttributes() { pthread_attr_destroy(&attr); } - pthread_attr_t* operator&() { return &attr; } - pthread_attr_t attr; -}; -} // namespace - -int ConvertToSystemPriority(ThreadPriority priority, int min_prio, - int max_prio) { - RTC_DCHECK(max_prio - min_prio > 2); - const int top_prio = max_prio - 1; - const int low_prio = min_prio + 1; - - switch (priority) { - case kLowPriority: - return low_prio; - case kNormalPriority: - // The -1 ensures that the kHighPriority is always greater or equal to - // kNormalPriority. - return (low_prio + top_prio - 1) / 2; - case kHighPriority: - return std::max(top_prio - 2, low_prio); - case kHighestPriority: - return std::max(top_prio - 1, low_prio); - case kRealtimePriority: - return top_prio; - } - RTC_DCHECK(false); - return low_prio; -} - -// static -void* ThreadPosix::StartThread(void* param) { - static_cast(param)->Run(); - return 0; -} - -ThreadPosix::ThreadPosix(ThreadRunFunction func, void* obj, - const char* thread_name) - : run_function_(func), - obj_(obj), - stop_event_(false, false), - name_(thread_name ? thread_name : "webrtc"), - thread_(0) { - RTC_DCHECK(name_.length() < 64); -} - -ThreadPosix::~ThreadPosix() { - RTC_DCHECK(thread_checker_.CalledOnValidThread()); -} - -// TODO(pbos): Make Start void, calling code really doesn't support failures -// here. -bool ThreadPosix::Start() { - RTC_DCHECK(thread_checker_.CalledOnValidThread()); - RTC_DCHECK(!thread_) << "Thread already started?"; - - ThreadAttributes attr; - // Set the stack stack size to 1M. - pthread_attr_setstacksize(&attr, 1024 * 1024); - RTC_CHECK_EQ(0, pthread_create(&thread_, &attr, &StartThread, this)); - return true; -} - -bool ThreadPosix::Stop() { - RTC_DCHECK(thread_checker_.CalledOnValidThread()); - if (!thread_) - return true; - - stop_event_.Set(); - RTC_CHECK_EQ(0, pthread_join(thread_, nullptr)); - thread_ = 0; - - return true; -} - -bool ThreadPosix::SetPriority(ThreadPriority priority) { - RTC_DCHECK(thread_checker_.CalledOnValidThread()); - if (!thread_) - return false; -#if defined(WEBRTC_CHROMIUM_BUILD) && defined(WEBRTC_LINUX) - // TODO(tommi): Switch to the same mechanism as Chromium uses for - // changing thread priorities. - return true; -#else -#ifdef WEBRTC_THREAD_RR - const int policy = SCHED_RR; -#else - const int policy = SCHED_FIFO; -#endif - const int min_prio = sched_get_priority_min(policy); - const int max_prio = sched_get_priority_max(policy); - if (min_prio == -1 || max_prio == -1) { - WEBRTC_TRACE(kTraceError, kTraceUtility, -1, - "unable to retreive min or max priority for threads"); - return false; - } - - if (max_prio - min_prio <= 2) - return false; - - sched_param param; - param.sched_priority = ConvertToSystemPriority(priority, min_prio, max_prio); - if (pthread_setschedparam(thread_, policy, ¶m) != 0) { - WEBRTC_TRACE( - kTraceError, kTraceUtility, -1, "unable to set thread priority"); - return false; - } - - return true; -#endif // defined(WEBRTC_CHROMIUM_BUILD) && defined(WEBRTC_LINUX) -} - -void ThreadPosix::Run() { - if (!name_.empty()) { - // Setting the thread name may fail (harmlessly) if running inside a - // sandbox. Ignore failures if they happen. - rtc::SetCurrentThreadName(name_.substr(0, 63).c_str()); - } - - // It's a requirement that for successful thread creation that the run - // function be called at least once (see RunFunctionIsCalled unit test), - // so to fullfill that requirement, we use a |do| loop and not |while|. - do { - if (!run_function_(obj_)) - break; - } while (!stop_event_.Wait(0)); -} - -} // namespace webrtc diff --git a/webrtc/system_wrappers/source/thread_posix.h b/webrtc/system_wrappers/source/thread_posix.h deleted file mode 100644 index bcdd732f86..0000000000 --- a/webrtc/system_wrappers/source/thread_posix.h +++ /dev/null @@ -1,53 +0,0 @@ -/* - * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved. - * - * Use of this source code is governed by a BSD-style license - * that can be found in the LICENSE file in the root of the source - * tree. An additional intellectual property rights grant can be found - * in the file PATENTS. All contributing project authors may - * be found in the AUTHORS file in the root of the source tree. - */ - -#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/include/thread_wrapper.h" - -#include - -namespace webrtc { - -int ConvertToSystemPriority(ThreadPriority priority, int min_prio, - int max_prio); - -class ThreadPosix : public ThreadWrapper { - public: - ThreadPosix(ThreadRunFunction func, void* obj, const char* thread_name); - ~ThreadPosix() override; - - // From ThreadWrapper. - bool Start() override; - bool Stop() override; - - bool SetPriority(ThreadPriority priority) override; - - private: - static void* StartThread(void* param); - - void Run(); - - rtc::ThreadChecker thread_checker_; - ThreadRunFunction const run_function_; - void* const obj_; - rtc::Event stop_event_; - const std::string name_; - - pthread_t thread_; -}; - -} // namespace webrtc - -#endif // WEBRTC_SYSTEM_WRAPPERS_SOURCE_THREAD_POSIX_H_ diff --git a/webrtc/system_wrappers/source/thread_posix_unittest.cc b/webrtc/system_wrappers/source/thread_posix_unittest.cc deleted file mode 100644 index edfb14502e..0000000000 --- a/webrtc/system_wrappers/source/thread_posix_unittest.cc +++ /dev/null @@ -1,30 +0,0 @@ -/* - * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved. - * - * Use of this source code is governed by a BSD-style license - * that can be found in the LICENSE file in the root of the source - * tree. An additional intellectual property rights grant can be found - * in the file PATENTS. All contributing project authors may - * be found in the AUTHORS file in the root of the source tree. - */ - -#include "webrtc/system_wrappers/source/thread_posix.h" - -#include "testing/gtest/include/gtest/gtest.h" - -TEST(ThreadTestPosix, PrioritySettings) { - // API assumes that max_prio - min_prio > 2. Test the extreme case. - const int kMinPrio = -1; - const int kMaxPrio = 2; - - int last_priority = kMinPrio; - for (int priority = webrtc::kLowPriority; - priority <= webrtc::kRealtimePriority; ++priority) { - int system_priority = webrtc::ConvertToSystemPriority( - static_cast(priority), kMinPrio, kMaxPrio); - EXPECT_GT(system_priority, kMinPrio); - EXPECT_LT(system_priority, kMaxPrio); - EXPECT_GE(system_priority, last_priority); - last_priority = system_priority; - } -} diff --git a/webrtc/system_wrappers/source/thread_win.cc b/webrtc/system_wrappers/source/thread_win.cc deleted file mode 100644 index b1c513c250..0000000000 --- a/webrtc/system_wrappers/source/thread_win.cc +++ /dev/null @@ -1,101 +0,0 @@ -/* - * Copyright (c) 2011 The WebRTC project authors. All Rights Reserved. - * - * Use of this source code is governed by a BSD-style license - * that can be found in the LICENSE file in the root of the source - * tree. An additional intellectual property rights grant can be found - * in the file PATENTS. All contributing project authors may - * be found in the AUTHORS file in the root of the source tree. - */ - -#include "webrtc/system_wrappers/source/thread_win.h" - -#include -#include -#include - -#include "webrtc/base/checks.h" -#include "webrtc/system_wrappers/include/trace.h" - -namespace webrtc { -namespace { -void CALLBACK RaiseFlag(ULONG_PTR param) { - *reinterpret_cast(param) = true; -} -} - -ThreadWindows::ThreadWindows(ThreadRunFunction func, void* obj, - const char* thread_name) - : run_function_(func), - obj_(obj), - stop_(false), - thread_(NULL), - name_(thread_name ? thread_name : "webrtc") { - RTC_DCHECK(func); -} - -ThreadWindows::~ThreadWindows() { - RTC_DCHECK(main_thread_.CalledOnValidThread()); - RTC_DCHECK(!thread_); -} - -// static -DWORD WINAPI ThreadWindows::StartThread(void* param) { - static_cast(param)->Run(); - return 0; -} - -bool ThreadWindows::Start() { - RTC_DCHECK(main_thread_.CalledOnValidThread()); - RTC_DCHECK(!thread_); - - stop_ = false; - - // 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); - if (!thread_ ) { - RTC_DCHECK(false) << "CreateThread failed"; - return false; - } - - return true; -} - -bool ThreadWindows::Stop() { - RTC_DCHECK(main_thread_.CalledOnValidThread()); - if (thread_) { - // Set stop_ to |true| on the worker thread. - QueueUserAPC(&RaiseFlag, thread_, reinterpret_cast(&stop_)); - WaitForSingleObject(thread_, INFINITE); - CloseHandle(thread_); - thread_ = nullptr; - } - - return true; -} - -bool ThreadWindows::SetPriority(ThreadPriority priority) { - RTC_DCHECK(main_thread_.CalledOnValidThread()); - return thread_ && SetThreadPriority(thread_, priority); -} - -void ThreadWindows::Run() { - if (!name_.empty()) - rtc::SetCurrentThreadName(name_.c_str()); - - do { - // The interface contract of Start/Stop is that for a successfull call to - // Start, there should be at least one call to the run function. So we - // call the function before checking |stop_|. - if (!run_function_(obj_)) - break; - // Alertable sleep to permit RaiseFlag to run and update |stop_|. - SleepEx(0, true); - } while (!stop_); -} - -} // namespace webrtc diff --git a/webrtc/system_wrappers/source/thread_win.h b/webrtc/system_wrappers/source/thread_win.h deleted file mode 100644 index 34edd6d6c0..0000000000 --- a/webrtc/system_wrappers/source/thread_win.h +++ /dev/null @@ -1,48 +0,0 @@ -/* - * Copyright (c) 2011 The WebRTC project authors. All Rights Reserved. - * - * Use of this source code is governed by a BSD-style license - * that can be found in the LICENSE file in the root of the source - * tree. An additional intellectual property rights grant can be found - * in the file PATENTS. All contributing project authors may - * be found in the AUTHORS file in the root of the source tree. - */ - -#ifndef WEBRTC_SYSTEM_WRAPPERS_SOURCE_THREAD_WIN_H_ -#define WEBRTC_SYSTEM_WRAPPERS_SOURCE_THREAD_WIN_H_ - -#include "webrtc/system_wrappers/include/thread_wrapper.h" - -#include - -#include "webrtc/base/thread_checker.h" - -namespace webrtc { - -class ThreadWindows : public ThreadWrapper { - public: - ThreadWindows(ThreadRunFunction func, void* obj, const char* thread_name); - ~ThreadWindows() override; - - bool Start() override; - bool Stop() override; - - bool SetPriority(ThreadPriority priority) override; - - protected: - void Run(); - - private: - static DWORD WINAPI StartThread(void* param); - - ThreadRunFunction const run_function_; - void* const obj_; - bool stop_; - HANDLE thread_; - const std::string name_; - rtc::ThreadChecker main_thread_; -}; - -} // namespace webrtc - -#endif // WEBRTC_SYSTEM_WRAPPERS_SOURCE_THREAD_WIN_H_ diff --git a/webrtc/system_wrappers/source/trace_impl.h b/webrtc/system_wrappers/source/trace_impl.h index ed49d9d0aa..c6d81d5b0b 100644 --- a/webrtc/system_wrappers/source/trace_impl.h +++ b/webrtc/system_wrappers/source/trace_impl.h @@ -16,7 +16,7 @@ #include "webrtc/system_wrappers/include/event_wrapper.h" #include "webrtc/system_wrappers/include/file_wrapper.h" #include "webrtc/system_wrappers/include/static_instance.h" -#include "webrtc/system_wrappers/include/thread_wrapper.h" +#include "webrtc/base/platform_thread.h" #include "webrtc/system_wrappers/include/trace.h" namespace webrtc { diff --git a/webrtc/system_wrappers/system_wrappers.gyp b/webrtc/system_wrappers/system_wrappers.gyp index 90ea79f80c..f5f2b2bdc8 100644 --- a/webrtc/system_wrappers/system_wrappers.gyp +++ b/webrtc/system_wrappers/system_wrappers.gyp @@ -44,7 +44,6 @@ 'include/static_instance.h', 'include/stl_util.h', 'include/stringize_macros.h', - 'include/thread_wrapper.h', 'include/tick_util.h', 'include/timestamp_extrapolator.h', 'include/trace.h', @@ -91,11 +90,6 @@ 'source/sleep.cc', 'source/sort.cc', 'source/tick_util.cc', - 'source/thread.cc', - 'source/thread_posix.cc', - 'source/thread_posix.h', - 'source/thread_win.cc', - 'source/thread_win.h', 'source/timestamp_extrapolator.cc', 'source/trace_impl.cc', 'source/trace_impl.h', diff --git a/webrtc/system_wrappers/system_wrappers_tests.gyp b/webrtc/system_wrappers/system_wrappers_tests.gyp index 02bf627779..7f735337eb 100644 --- a/webrtc/system_wrappers/system_wrappers_tests.gyp +++ b/webrtc/system_wrappers/system_wrappers_tests.gyp @@ -33,8 +33,6 @@ 'source/scoped_vector_unittest.cc', 'source/stringize_macros_unittest.cc', 'source/stl_util_unittest.cc', - 'source/thread_unittest.cc', - 'source/thread_posix_unittest.cc', ], 'conditions': [ ['enable_data_logging==1', { @@ -42,9 +40,6 @@ }, { 'sources!': [ 'source/data_log_unittest.cc', ], }], - ['os_posix==0', { - 'sources!': [ 'source/thread_posix_unittest.cc', ], - }], ['OS=="android"', { 'dependencies': [ '<(DEPTH)/testing/android/native_test.gyp:native_test_native_code', diff --git a/webrtc/test/channel_transport/udp_socket2_manager_win.cc b/webrtc/test/channel_transport/udp_socket2_manager_win.cc index 5a11abbd6e..bd466a24ca 100644 --- a/webrtc/test/channel_transport/udp_socket2_manager_win.cc +++ b/webrtc/test/channel_transport/udp_socket2_manager_win.cc @@ -556,7 +556,7 @@ int32_t UdpSocket2WorkerWindows::Init() if(!_init) { const char* threadName = "UdpSocket2ManagerWindows_thread"; - _pThread = ThreadWrapper::CreateThread(Run, this, threadName); + _pThread = PlatformThread::CreateThread(Run, this, threadName); _init = true; } return 0; diff --git a/webrtc/test/channel_transport/udp_socket2_manager_win.h b/webrtc/test/channel_transport/udp_socket2_manager_win.h index c6af03a702..9cfc0f0e92 100644 --- a/webrtc/test/channel_transport/udp_socket2_manager_win.h +++ b/webrtc/test/channel_transport/udp_socket2_manager_win.h @@ -17,7 +17,7 @@ #include "webrtc/system_wrappers/include/atomic32.h" #include "webrtc/system_wrappers/include/critical_section_wrapper.h" #include "webrtc/system_wrappers/include/event_wrapper.h" -#include "webrtc/system_wrappers/include/thread_wrapper.h" +#include "webrtc/base/platform_thread.h" #include "webrtc/test/channel_transport/udp_socket2_win.h" #include "webrtc/test/channel_transport/udp_socket_manager_wrapper.h" #include "webrtc/test/channel_transport/udp_transport.h" @@ -47,7 +47,7 @@ struct PerIoContext { int fromLen; // Should be set to true if the I/O context was passed to the system by // a thread not controlled by the socket implementation. - bool ioInitiatedByThreadWrapper; + bool ioInitiatedByPlatformThread; // TODO (hellner): Not used. Delete it. PerIoContext* pNextFree; }; @@ -105,7 +105,7 @@ protected: bool Process(); private: HANDLE _ioCompletionHandle; - rtc::scoped_ptr _pThread; + rtc::scoped_ptr _pThread; static int32_t _numOfWorkers; int32_t _workerNumber; volatile bool _stop; diff --git a/webrtc/test/channel_transport/udp_socket2_win.cc b/webrtc/test/channel_transport/udp_socket2_win.cc index 4c63dc938d..adeb46a9d2 100644 --- a/webrtc/test/channel_transport/udp_socket2_win.cc +++ b/webrtc/test/channel_transport/udp_socket2_win.cc @@ -432,13 +432,13 @@ void UdpSocket2Windows::IOCompleted(PerIoContext* pIOContext, if(pIOContext == NULL || error == ERROR_OPERATION_ABORTED) { if ((pIOContext != NULL) && - !pIOContext->ioInitiatedByThreadWrapper && + !pIOContext->ioInitiatedByPlatformThread && (error == ERROR_OPERATION_ABORTED) && (pIOContext->ioOperation == OP_READ) && _outstandingCallsDisabled) { - // !pIOContext->initiatedIOByThreadWrapper indicate that the I/O - // was not initiated by a ThreadWrapper thread. + // !pIOContext->initiatedIOByPlatformThread indicate that the I/O + // was not initiated by a PlatformThread thread. // This may happen if the thread that initiated receiving (e.g. // by calling StartListen())) is deleted before any packets have // been received. @@ -519,7 +519,7 @@ void UdpSocket2Windows::IOCompleted(PerIoContext* pIOContext, { // The PerIoContext was posted by a thread controlled by the socket // implementation. - pIOContext->ioInitiatedByThreadWrapper = true; + pIOContext->ioInitiatedByPlatformThread = true; } OutstandingCallCompleted(); return; @@ -546,7 +546,7 @@ int32_t UdpSocket2Windows::PostRecv() } // This function may have been called by thread not controlled by the socket // implementation. - pIoContext->ioInitiatedByThreadWrapper = false; + pIoContext->ioInitiatedByPlatformThread = false; return PostRecv(pIoContext); } diff --git a/webrtc/test/channel_transport/udp_socket_manager_posix.cc b/webrtc/test/channel_transport/udp_socket_manager_posix.cc index 145efcbc58..6b597e761c 100644 --- a/webrtc/test/channel_transport/udp_socket_manager_posix.cc +++ b/webrtc/test/channel_transport/udp_socket_manager_posix.cc @@ -188,8 +188,8 @@ bool UdpSocketManagerPosix::RemoveSocket(UdpSocketWrapper* s) UdpSocketManagerPosixImpl::UdpSocketManagerPosixImpl() { _critSectList = CriticalSectionWrapper::CreateCriticalSection(); - _thread = ThreadWrapper::CreateThread(UdpSocketManagerPosixImpl::Run, this, - "UdpSocketManagerPosixImplThread"); + _thread = PlatformThread::CreateThread(UdpSocketManagerPosixImpl::Run, this, + "UdpSocketManagerPosixImplThread"); FD_ZERO(&_readFds); WEBRTC_TRACE(kTraceMemory, kTraceTransport, -1, "UdpSocketManagerPosix created"); diff --git a/webrtc/test/channel_transport/udp_socket_manager_posix.h b/webrtc/test/channel_transport/udp_socket_manager_posix.h index 64156fd20f..0750a4a967 100644 --- a/webrtc/test/channel_transport/udp_socket_manager_posix.h +++ b/webrtc/test/channel_transport/udp_socket_manager_posix.h @@ -17,8 +17,8 @@ #include #include +#include "webrtc/base/platform_thread.h" #include "webrtc/system_wrappers/include/critical_section_wrapper.h" -#include "webrtc/system_wrappers/include/thread_wrapper.h" #include "webrtc/test/channel_transport/udp_socket_manager_wrapper.h" #include "webrtc/test/channel_transport/udp_socket_wrapper.h" @@ -75,7 +75,7 @@ protected: private: typedef std::list SocketList; typedef std::list FdList; - rtc::scoped_ptr _thread; + rtc::scoped_ptr _thread; CriticalSectionWrapper* _critSectList; fd_set _readFds; diff --git a/webrtc/test/direct_transport.cc b/webrtc/test/direct_transport.cc index 6dcba81c88..837281b734 100644 --- a/webrtc/test/direct_transport.cc +++ b/webrtc/test/direct_transport.cc @@ -21,7 +21,7 @@ DirectTransport::DirectTransport(Call* send_call) : send_call_(send_call), packet_event_(EventWrapper::Create()), thread_( - ThreadWrapper::CreateThread(NetworkProcess, this, "NetworkProcess")), + PlatformThread::CreateThread(NetworkProcess, this, "NetworkProcess")), clock_(Clock::GetRealTimeClock()), shutting_down_(false), fake_network_(FakeNetworkPipe::Config()) { @@ -33,7 +33,7 @@ DirectTransport::DirectTransport(const FakeNetworkPipe::Config& config, : send_call_(send_call), packet_event_(EventWrapper::Create()), thread_( - ThreadWrapper::CreateThread(NetworkProcess, this, "NetworkProcess")), + PlatformThread::CreateThread(NetworkProcess, this, "NetworkProcess")), clock_(Clock::GetRealTimeClock()), shutting_down_(false), fake_network_(config) { diff --git a/webrtc/test/direct_transport.h b/webrtc/test/direct_transport.h index 241a5bc110..d3cc084d07 100644 --- a/webrtc/test/direct_transport.h +++ b/webrtc/test/direct_transport.h @@ -15,9 +15,9 @@ #include #include "webrtc/base/criticalsection.h" +#include "webrtc/base/platform_thread.h" #include "webrtc/base/scoped_ptr.h" #include "webrtc/system_wrappers/include/event_wrapper.h" -#include "webrtc/system_wrappers/include/thread_wrapper.h" #include "webrtc/test/fake_network_pipe.h" #include "webrtc/transport.h" @@ -53,7 +53,7 @@ class DirectTransport : public Transport { rtc::CriticalSection lock_; Call* const send_call_; rtc::scoped_ptr packet_event_; - rtc::scoped_ptr thread_; + rtc::scoped_ptr thread_; Clock* const clock_; bool shutting_down_; diff --git a/webrtc/test/fake_audio_device.cc b/webrtc/test/fake_audio_device.cc index 4408804037..4eee6606a3 100644 --- a/webrtc/test/fake_audio_device.cc +++ b/webrtc/test/fake_audio_device.cc @@ -13,11 +13,11 @@ #include #include "testing/gtest/include/gtest/gtest.h" +#include "webrtc/base/platform_thread.h" #include "webrtc/modules/media_file/media_file_utility.h" #include "webrtc/system_wrappers/include/clock.h" #include "webrtc/system_wrappers/include/event_wrapper.h" #include "webrtc/system_wrappers/include/file_wrapper.h" -#include "webrtc/system_wrappers/include/thread_wrapper.h" namespace webrtc { namespace test { @@ -53,8 +53,8 @@ int32_t FakeAudioDevice::Init() { if (!tick_->StartTimer(true, 10)) return -1; - thread_ = ThreadWrapper::CreateThread(FakeAudioDevice::Run, this, - "FakeAudioDevice"); + thread_ = PlatformThread::CreateThread(FakeAudioDevice::Run, this, + "FakeAudioDevice"); if (thread_.get() == NULL) return -1; if (!thread_->Start()) { diff --git a/webrtc/test/fake_audio_device.h b/webrtc/test/fake_audio_device.h index bdc672892c..9733da36bb 100644 --- a/webrtc/test/fake_audio_device.h +++ b/webrtc/test/fake_audio_device.h @@ -23,7 +23,7 @@ class Clock; class EventTimerWrapper; class FileWrapper; class ModuleFileUtility; -class ThreadWrapper; +class PlatformThread; namespace test { @@ -59,7 +59,7 @@ class FakeAudioDevice : public FakeAudioDeviceModule { Clock* clock_; rtc::scoped_ptr tick_; mutable rtc::CriticalSection lock_; - rtc::scoped_ptr thread_; + rtc::scoped_ptr thread_; rtc::scoped_ptr file_utility_; rtc::scoped_ptr input_stream_; }; diff --git a/webrtc/test/frame_generator_capturer.cc b/webrtc/test/frame_generator_capturer.cc index 70e2c85698..cc0ad88f03 100644 --- a/webrtc/test/frame_generator_capturer.cc +++ b/webrtc/test/frame_generator_capturer.cc @@ -11,11 +11,11 @@ #include "webrtc/test/frame_generator_capturer.h" #include "webrtc/base/criticalsection.h" -#include "webrtc/test/frame_generator.h" +#include "webrtc/base/platform_thread.h" #include "webrtc/system_wrappers/include/clock.h" #include "webrtc/system_wrappers/include/event_wrapper.h" #include "webrtc/system_wrappers/include/sleep.h" -#include "webrtc/system_wrappers/include/thread_wrapper.h" +#include "webrtc/test/frame_generator.h" #include "webrtc/video_send_stream.h" namespace webrtc { @@ -88,8 +88,8 @@ bool FrameGeneratorCapturer::Init() { if (!tick_->StartTimer(true, 1000 / target_fps_)) return false; - thread_ = ThreadWrapper::CreateThread(FrameGeneratorCapturer::Run, this, - "FrameGeneratorCapturer"); + thread_ = PlatformThread::CreateThread(FrameGeneratorCapturer::Run, this, + "FrameGeneratorCapturer"); if (thread_.get() == NULL) return false; if (!thread_->Start()) { diff --git a/webrtc/test/frame_generator_capturer.h b/webrtc/test/frame_generator_capturer.h index aff906dfa2..73c97a69a6 100644 --- a/webrtc/test/frame_generator_capturer.h +++ b/webrtc/test/frame_generator_capturer.h @@ -21,7 +21,7 @@ namespace webrtc { class CriticalSectionWrapper; class EventTimerWrapper; -class ThreadWrapper; +class PlatformThread; namespace test { @@ -64,7 +64,7 @@ class FrameGeneratorCapturer : public VideoCapturer { rtc::scoped_ptr tick_; rtc::CriticalSection lock_; - rtc::scoped_ptr thread_; + rtc::scoped_ptr thread_; rtc::scoped_ptr frame_generator_; int target_fps_; diff --git a/webrtc/video/rampup_tests.cc b/webrtc/video/rampup_tests.cc index c9b8e11122..fc0d0cb4f2 100644 --- a/webrtc/video/rampup_tests.cc +++ b/webrtc/video/rampup_tests.cc @@ -12,6 +12,7 @@ #include "webrtc/base/checks.h" #include "webrtc/base/common.h" #include "webrtc/base/event.h" +#include "webrtc/base/platform_thread.h" #include "webrtc/modules/pacing/packet_router.h" #include "webrtc/modules/remote_bitrate_estimator/remote_bitrate_estimator_abs_send_time.h" #include "webrtc/modules/remote_bitrate_estimator/remote_bitrate_estimator_single_stream.h" @@ -22,7 +23,6 @@ #include "webrtc/modules/rtp_rtcp/include/rtp_rtcp.h" #include "webrtc/modules/rtp_rtcp/source/rtcp_utility.h" #include "webrtc/system_wrappers/include/critical_section_wrapper.h" -#include "webrtc/system_wrappers/include/thread_wrapper.h" #include "webrtc/test/testsupport/perf_test.h" #include "webrtc/video/rampup_tests.h" @@ -60,9 +60,9 @@ RampUpTester::RampUpTester(size_t num_streams, extension_type_(extension_type), ssrcs_(GenerateSsrcs(num_streams, 100)), rtx_ssrcs_(GenerateSsrcs(num_streams, 200)), - poller_thread_(ThreadWrapper::CreateThread(&BitrateStatsPollingThread, - this, - "BitrateStatsPollingThread")), + poller_thread_(PlatformThread::CreateThread(&BitrateStatsPollingThread, + this, + "BitrateStatsPollingThread")), sender_call_(nullptr) { if (rtx_) { for (size_t i = 0; i < ssrcs_.size(); ++i) diff --git a/webrtc/video/rampup_tests.h b/webrtc/video/rampup_tests.h index ff65c8d0a0..3632a81ca5 100644 --- a/webrtc/video/rampup_tests.h +++ b/webrtc/video/rampup_tests.h @@ -98,7 +98,7 @@ class RampUpTester : public test::EndToEndTest { std::vector rtx_ssrcs_; SsrcMap rtx_ssrc_map_; - rtc::scoped_ptr poller_thread_; + rtc::scoped_ptr poller_thread_; Call* sender_call_; }; diff --git a/webrtc/video/video_capture_input.cc b/webrtc/video/video_capture_input.cc index 37ea07ec93..d15932d15f 100644 --- a/webrtc/video/video_capture_input.cc +++ b/webrtc/video/video_capture_input.cc @@ -42,9 +42,9 @@ VideoCaptureInput::VideoCaptureInput( local_renderer_(local_renderer), stats_proxy_(stats_proxy), incoming_frame_cs_(CriticalSectionWrapper::CreateCriticalSection()), - encoder_thread_(ThreadWrapper::CreateThread(EncoderThreadFunction, - this, - "EncoderThread")), + encoder_thread_(PlatformThread::CreateThread(EncoderThreadFunction, + this, + "EncoderThread")), capture_event_(EventWrapper::Create()), stop_(0), last_captured_timestamp_(0), diff --git a/webrtc/video/video_capture_input.h b/webrtc/video/video_capture_input.h index 22a8ddc4d4..2cdcbf8060 100644 --- a/webrtc/video/video_capture_input.h +++ b/webrtc/video/video_capture_input.h @@ -14,6 +14,7 @@ #include #include "webrtc/base/criticalsection.h" +#include "webrtc/base/platform_thread.h" #include "webrtc/base/scoped_ptr.h" #include "webrtc/base/thread_annotations.h" #include "webrtc/common_types.h" @@ -23,7 +24,6 @@ #include "webrtc/modules/video_coding/include/video_coding.h" #include "webrtc/modules/video_processing/include/video_processing.h" #include "webrtc/system_wrappers/include/critical_section_wrapper.h" -#include "webrtc/system_wrappers/include/thread_wrapper.h" #include "webrtc/typedefs.h" #include "webrtc/video_send_stream.h" @@ -78,7 +78,7 @@ class VideoCaptureInput : public webrtc::VideoCaptureInput { rtc::scoped_ptr incoming_frame_cs_; VideoFrame incoming_frame_; - rtc::scoped_ptr encoder_thread_; + rtc::scoped_ptr encoder_thread_; rtc::scoped_ptr capture_event_; volatile int stop_; diff --git a/webrtc/video/video_quality_test.cc b/webrtc/video/video_quality_test.cc index 878beed75e..da522970dc 100644 --- a/webrtc/video/video_quality_test.cc +++ b/webrtc/video/video_quality_test.cc @@ -91,18 +91,18 @@ class VideoAnalyzer : public PacketReceiver, } for (uint32_t i = 0; i < num_cores; ++i) { - rtc::scoped_ptr thread = - ThreadWrapper::CreateThread(&FrameComparisonThread, this, "Analyzer"); + rtc::scoped_ptr thread = PlatformThread::CreateThread( + &FrameComparisonThread, this, "Analyzer"); EXPECT_TRUE(thread->Start()); comparison_thread_pool_.push_back(thread.release()); } stats_polling_thread_ = - ThreadWrapper::CreateThread(&PollStatsThread, this, "StatsPoller"); + PlatformThread::CreateThread(&PollStatsThread, this, "StatsPoller"); } ~VideoAnalyzer() { - for (ThreadWrapper* thread : comparison_thread_pool_) { + for (PlatformThread* thread : comparison_thread_pool_) { EXPECT_TRUE(thread->Stop()); delete thread; } @@ -602,8 +602,8 @@ class VideoAnalyzer : public PacketReceiver, const double avg_ssim_threshold_; rtc::CriticalSection comparison_lock_; - std::vector comparison_thread_pool_; - rtc::scoped_ptr stats_polling_thread_; + std::vector comparison_thread_pool_; + rtc::scoped_ptr stats_polling_thread_; const rtc::scoped_ptr comparison_available_event_; std::deque comparisons_ GUARDED_BY(comparison_lock_); const rtc::scoped_ptr done_; diff --git a/webrtc/video/video_send_stream_tests.cc b/webrtc/video/video_send_stream_tests.cc index a1d74757f0..eefcfebc18 100644 --- a/webrtc/video/video_send_stream_tests.cc +++ b/webrtc/video/video_send_stream_tests.cc @@ -16,6 +16,7 @@ #include "webrtc/base/checks.h" #include "webrtc/base/criticalsection.h" #include "webrtc/base/logging.h" +#include "webrtc/base/platform_thread.h" #include "webrtc/base/scoped_ptr.h" #include "webrtc/call.h" #include "webrtc/call/transport_adapter.h" @@ -30,7 +31,6 @@ #include "webrtc/system_wrappers/include/event_wrapper.h" #include "webrtc/system_wrappers/include/ref_count.h" #include "webrtc/system_wrappers/include/sleep.h" -#include "webrtc/system_wrappers/include/thread_wrapper.h" #include "webrtc/test/call_test.h" #include "webrtc/test/configurable_frame_size_encoder.h" #include "webrtc/test/fake_texture_frame.h" diff --git a/webrtc/video_engine/vie_channel.cc b/webrtc/video_engine/vie_channel.cc index 4cfd0f0ee5..2e56056b5f 100644 --- a/webrtc/video_engine/vie_channel.cc +++ b/webrtc/video_engine/vie_channel.cc @@ -15,6 +15,7 @@ #include "webrtc/base/checks.h" #include "webrtc/base/logging.h" +#include "webrtc/base/platform_thread.h" #include "webrtc/common.h" #include "webrtc/common_video/include/incoming_video_stream.h" #include "webrtc/common_video/libyuv/include/webrtc_libyuv.h" @@ -29,7 +30,6 @@ #include "webrtc/modules/video_render/video_render_defines.h" #include "webrtc/system_wrappers/include/critical_section_wrapper.h" #include "webrtc/system_wrappers/include/metrics.h" -#include "webrtc/system_wrappers/include/thread_wrapper.h" #include "webrtc/video/receive_statistics_proxy.h" #include "webrtc/video_engine/call_stats.h" #include "webrtc/video_engine/payload_router.h" @@ -1150,8 +1150,8 @@ void ViEChannel::StartDecodeThread() { // Start the decode thread if (decode_thread_) return; - decode_thread_ = ThreadWrapper::CreateThread(ChannelDecodeThreadFunction, - this, "DecodingThread"); + decode_thread_ = PlatformThread::CreateThread(ChannelDecodeThreadFunction, + this, "DecodingThread"); decode_thread_->Start(); decode_thread_->SetPriority(kHighestPriority); } diff --git a/webrtc/video_engine/vie_channel.h b/webrtc/video_engine/vie_channel.h index 472dbc8123..32f0301707 100644 --- a/webrtc/video_engine/vie_channel.h +++ b/webrtc/video_engine/vie_channel.h @@ -41,7 +41,7 @@ class ProcessThread; class ReceiveStatisticsProxy; class ReportBlockStats; class RtcpRttStats; -class ThreadWrapper; +class PlatformThread; class ViEChannelProtectionCallback; class ViERTPObserver; class VideoCodingModule; @@ -433,7 +433,7 @@ class ViEChannel : public VCMFrameTypeCallback, const rtc::scoped_ptr bandwidth_observer_; TransportFeedbackObserver* const transport_feedback_observer_; - rtc::scoped_ptr decode_thread_; + rtc::scoped_ptr decode_thread_; int nack_history_size_sender_; int max_nack_reordering_threshold_; diff --git a/webrtc/voice_engine/test/android/android_test/jni/android_test.cc b/webrtc/voice_engine/test/android/android_test/jni/android_test.cc index ceafca9da3..55dfa15f51 100644 --- a/webrtc/voice_engine/test/android/android_test/jni/android_test.cc +++ b/webrtc/voice_engine/test/android/android_test/jni/android_test.cc @@ -15,7 +15,7 @@ #include "webrtc/voice_engine/test/android/android_test/jni/org_webrtc_voiceengine_test_AndroidTest.h" -#include "webrtc/system_wrappers/include/thread_wrapper.h" +#include "webrtc/base/platform_thread.h" #include "webrtc/voice_engine/include/voe_audio_processing.h" #include "webrtc/voice_engine/include/voe_base.h" @@ -177,7 +177,7 @@ private: static bool Run(void* ptr); bool Process(); private: - rtc::scoped_ptr _thread; + rtc::scoped_ptr _thread; }; ThreadTest::~ThreadTest() @@ -188,7 +188,7 @@ ThreadTest::~ThreadTest() ThreadTest::ThreadTest() { - _thread = ThreadWrapper::CreateThread(Run, this, "ThreadTest thread"); + _thread = PlatformThread::CreateThread(Run, this, "ThreadTest thread"); } bool ThreadTest::Run(void* ptr) diff --git a/webrtc/voice_engine/test/auto_test/fakes/conference_transport.cc b/webrtc/voice_engine/test/auto_test/fakes/conference_transport.cc index 28ab352608..e360d41802 100644 --- a/webrtc/voice_engine/test/auto_test/fakes/conference_transport.cc +++ b/webrtc/voice_engine/test/auto_test/fakes/conference_transport.cc @@ -40,9 +40,9 @@ ConferenceTransport::ConferenceTransport() : pq_crit_(webrtc::CriticalSectionWrapper::CreateCriticalSection()), stream_crit_(webrtc::CriticalSectionWrapper::CreateCriticalSection()), packet_event_(webrtc::EventWrapper::Create()), - thread_(webrtc::ThreadWrapper::CreateThread(Run, - this, - "ConferenceTransport")), + thread_(webrtc::PlatformThread::CreateThread(Run, + this, + "ConferenceTransport")), rtt_ms_(0), stream_count_(0), rtp_header_parser_(webrtc::RtpHeaderParser::Create()) { diff --git a/webrtc/voice_engine/test/auto_test/fakes/conference_transport.h b/webrtc/voice_engine/test/auto_test/fakes/conference_transport.h index fb430eba4d..b9b4e76f16 100644 --- a/webrtc/voice_engine/test/auto_test/fakes/conference_transport.h +++ b/webrtc/voice_engine/test/auto_test/fakes/conference_transport.h @@ -17,12 +17,12 @@ #include "testing/gtest/include/gtest/gtest.h" #include "webrtc/base/basictypes.h" +#include "webrtc/base/platform_thread.h" #include "webrtc/base/scoped_ptr.h" #include "webrtc/common_types.h" #include "webrtc/modules/rtp_rtcp/include/rtp_header_parser.h" #include "webrtc/system_wrappers/include/critical_section_wrapper.h" #include "webrtc/system_wrappers/include/event_wrapper.h" -#include "webrtc/system_wrappers/include/thread_wrapper.h" #include "webrtc/voice_engine/include/voe_base.h" #include "webrtc/voice_engine/include/voe_codec.h" #include "webrtc/voice_engine/include/voe_file.h" @@ -131,7 +131,7 @@ class ConferenceTransport: public webrtc::Transport { const rtc::scoped_ptr pq_crit_; const rtc::scoped_ptr stream_crit_; const rtc::scoped_ptr packet_event_; - const rtc::scoped_ptr thread_; + const rtc::scoped_ptr thread_; unsigned int rtt_ms_; unsigned int stream_count_; diff --git a/webrtc/voice_engine/test/auto_test/fixtures/after_initialization_fixture.h b/webrtc/voice_engine/test/auto_test/fixtures/after_initialization_fixture.h index 1a1075c585..7b4bc638a6 100644 --- a/webrtc/voice_engine/test/auto_test/fixtures/after_initialization_fixture.h +++ b/webrtc/voice_engine/test/auto_test/fixtures/after_initialization_fixture.h @@ -13,6 +13,7 @@ #include +#include "webrtc/base/platform_thread.h" #include "webrtc/base/scoped_ptr.h" #include "webrtc/common_types.h" #include "webrtc/modules/rtp_rtcp/source/byte_io.h" @@ -20,7 +21,6 @@ #include "webrtc/system_wrappers/include/critical_section_wrapper.h" #include "webrtc/system_wrappers/include/event_wrapper.h" #include "webrtc/system_wrappers/include/sleep.h" -#include "webrtc/system_wrappers/include/thread_wrapper.h" #include "webrtc/voice_engine/test/auto_test/fixtures/before_initialization_fixture.h" class TestErrorObserver; @@ -30,9 +30,9 @@ class LoopBackTransport : public webrtc::Transport { LoopBackTransport(webrtc::VoENetwork* voe_network, int channel) : crit_(webrtc::CriticalSectionWrapper::CreateCriticalSection()), packet_event_(webrtc::EventWrapper::Create()), - thread_(webrtc::ThreadWrapper::CreateThread(NetworkProcess, - this, - "LoopBackTransport")), + thread_(webrtc::PlatformThread::CreateThread(NetworkProcess, + this, + "LoopBackTransport")), channel_(channel), voe_network_(voe_network), transmitted_packets_(0) { @@ -147,7 +147,7 @@ class LoopBackTransport : public webrtc::Transport { const rtc::scoped_ptr crit_; const rtc::scoped_ptr packet_event_; - const rtc::scoped_ptr thread_; + const rtc::scoped_ptr thread_; std::deque packet_queue_ GUARDED_BY(crit_.get()); const int channel_; std::map channels_ GUARDED_BY(crit_.get()); diff --git a/webrtc/voice_engine/test/auto_test/voe_standard_test.h b/webrtc/voice_engine/test/auto_test/voe_standard_test.h index 3bf89362d5..e60107c1e4 100644 --- a/webrtc/voice_engine/test/auto_test/voe_standard_test.h +++ b/webrtc/voice_engine/test/auto_test/voe_standard_test.h @@ -44,7 +44,7 @@ #ifdef WEBRTC_VOICE_ENGINE_NETEQ_STATS_API namespace webrtc { class CriticalSectionWrapper; -class ThreadWrapper; +class PlatformThread; class VoENetEqStats; } #endif diff --git a/webrtc/voice_engine/test/auto_test/voe_stress_test.cc b/webrtc/voice_engine/test/auto_test/voe_stress_test.cc index b9e71159ab..91b39ebd22 100644 --- a/webrtc/voice_engine/test/auto_test/voe_stress_test.cc +++ b/webrtc/voice_engine/test/auto_test/voe_stress_test.cc @@ -334,8 +334,8 @@ int VoEStressTest::MultipleThreadsTest() { int rnd(0); // Start extra thread - _ptrExtraApiThread = ThreadWrapper::CreateThread(RunExtraApi, this, - "StressTestExtraApiThread"); + _ptrExtraApiThread = PlatformThread::CreateThread(RunExtraApi, this, + "StressTestExtraApiThread"); VALIDATE_STRESS(!_ptrExtraApiThread->Start()); // Some possible extensions include: diff --git a/webrtc/voice_engine/test/auto_test/voe_stress_test.h b/webrtc/voice_engine/test/auto_test/voe_stress_test.h index 69b3a92bb3..b69e8da39d 100644 --- a/webrtc/voice_engine/test/auto_test/voe_stress_test.h +++ b/webrtc/voice_engine/test/auto_test/voe_stress_test.h @@ -11,7 +11,7 @@ #ifndef WEBRTC_VOICE_ENGINE_VOE_STRESS_TEST_H #define WEBRTC_VOICE_ENGINE_VOE_STRESS_TEST_H -#include "webrtc/system_wrappers/include/thread_wrapper.h" +#include "webrtc/base/platform_thread.h" namespace voetest { // TODO(andrew): using directives are not permitted. @@ -38,7 +38,7 @@ class VoEStressTest { VoETestManager& _mgr; - rtc::scoped_ptr _ptrExtraApiThread; + rtc::scoped_ptr _ptrExtraApiThread; }; } // namespace voetest