diff options
author | pbos <pbos@webrtc.org> | 2015-11-23 14:47:56 -0800 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2015-11-23 22:48:01 +0000 |
commit | 12411ef40e08c5e28ccde54ab3418c96676ffcbc (patch) | |
tree | 7e5ea8c92aff06e38fd43095302855bd2f8950a0 /webrtc/system_wrappers | |
parent | 255d6f6fb28f78a5b77f4b4ee0da24524e4371c6 (diff) | |
download | webrtc-12411ef40e08c5e28ccde54ab3418c96676ffcbc.tar.gz |
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}
Diffstat (limited to 'webrtc/system_wrappers')
18 files changed, 16 insertions, 601 deletions
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 <string> #include <vector> +#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<ThreadWrapper> file_writer_thread_; + rtc::scoped_ptr<PlatformThread> 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 <windows.h> -#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<ThreadWrapper> 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<ThreadWrapper> thread_; + rtc::scoped_ptr<PlatformThread> 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<ThreadWrapper> thread = ThreadWrapper::CreateThread( + rtc::scoped_ptr<PlatformThread> 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<ThreadWrapper> thread = ThreadWrapper::CreateThread( + rtc::scoped_ptr<PlatformThread> 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 <pthread.h> #include <time.h> -#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<ThreadWrapper> timer_thread_; + rtc::scoped_ptr<PlatformThread> timer_thread_; rtc::scoped_ptr<EventTimerPosix> 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> ThreadWrapper::CreateThread( - ThreadRunFunction func, void* obj, const char* thread_name) { - return rtc::scoped_ptr<ThreadWrapper>( - 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 <algorithm> - -#include <errno.h> -#include <unistd.h> -#ifdef WEBRTC_LINUX -#include <linux/unistd.h> -#include <sched.h> -#include <sys/types.h> -#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<ThreadPosix*>(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 <pthread.h> - -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<webrtc::ThreadPriority>(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_unittest.cc b/webrtc/system_wrappers/source/thread_unittest.cc deleted file mode 100644 index c8e180ba32..0000000000 --- a/webrtc/system_wrappers/source/thread_unittest.cc +++ /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. - */ - -#include "webrtc/system_wrappers/include/thread_wrapper.h" - -#include "testing/gtest/include/gtest/gtest.h" -#include "webrtc/base/scoped_ptr.h" -#include "webrtc/system_wrappers/include/sleep.h" - -namespace webrtc { - -// Function that does nothing, and reports success. -bool NullRunFunction(void* obj) { - SleepMs(0); // Hand over timeslice, prevents busy looping. - return true; -} - -TEST(ThreadTest, StartStop) { - rtc::scoped_ptr<ThreadWrapper> thread = ThreadWrapper::CreateThread( - &NullRunFunction, nullptr, "ThreadTest"); - ASSERT_TRUE(thread->Start()); - EXPECT_TRUE(thread->Stop()); -} - -// Function that sets a boolean. -bool SetFlagRunFunction(void* obj) { - bool* obj_as_bool = static_cast<bool*>(obj); - *obj_as_bool = true; - SleepMs(0); // Hand over timeslice, prevents busy looping. - return true; -} - -TEST(ThreadTest, RunFunctionIsCalled) { - bool flag = false; - rtc::scoped_ptr<ThreadWrapper> thread = ThreadWrapper::CreateThread( - &SetFlagRunFunction, &flag, "RunFunctionIsCalled"); - ASSERT_TRUE(thread->Start()); - - // At this point, the flag may be either true or false. - EXPECT_TRUE(thread->Stop()); - - // We expect the thread to have run at least once. - EXPECT_TRUE(flag); -} - -} // namespace webrtc 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 <process.h> -#include <stdio.h> -#include <windows.h> - -#include "webrtc/base/checks.h" -#include "webrtc/system_wrappers/include/trace.h" - -namespace webrtc { -namespace { -void CALLBACK RaiseFlag(ULONG_PTR param) { - *reinterpret_cast<bool*>(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<ThreadWindows*>(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<ULONG_PTR>(&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 <windows.h> - -#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', |