Delete unused class SignalThread
Bug: webrtc:6424 Change-Id: I96ccc7fc1d30ad28eb14ff24f04119d248f43eb9 Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/206460 Reviewed-by: Mirko Bonadei <mbonadei@webrtc.org> Reviewed-by: Markus Handell <handellm@webrtc.org> Reviewed-by: Tommi <tommi@webrtc.org> Commit-Queue: Niels Moller <nisse@webrtc.org> Cr-Commit-Position: refs/heads/master@{#33231}
This commit is contained in:
@ -17,7 +17,6 @@
|
|||||||
|
|
||||||
#include "rtc_base/net_helpers.h"
|
#include "rtc_base/net_helpers.h"
|
||||||
#include "rtc_base/physical_socket_server.h"
|
#include "rtc_base/physical_socket_server.h"
|
||||||
#include "rtc_base/signal_thread.h"
|
|
||||||
#include "rtc_base/third_party/sigslot/sigslot.h"
|
#include "rtc_base/third_party/sigslot/sigslot.h"
|
||||||
|
|
||||||
typedef std::map<int, std::string> Peers;
|
typedef std::map<int, std::string> Peers;
|
||||||
|
@ -772,9 +772,6 @@ rtc_library("threading") {
|
|||||||
"network_monitor_factory.h",
|
"network_monitor_factory.h",
|
||||||
"physical_socket_server.cc",
|
"physical_socket_server.cc",
|
||||||
"physical_socket_server.h",
|
"physical_socket_server.h",
|
||||||
|
|
||||||
# "signal_thread.cc",
|
|
||||||
# "signal_thread.h",
|
|
||||||
"thread.cc",
|
"thread.cc",
|
||||||
"thread.h",
|
"thread.h",
|
||||||
"thread_message.h",
|
"thread_message.h",
|
||||||
@ -967,8 +964,6 @@ rtc_library("rtc_base") {
|
|||||||
"crypt_string.h",
|
"crypt_string.h",
|
||||||
"data_rate_limiter.cc",
|
"data_rate_limiter.cc",
|
||||||
"data_rate_limiter.h",
|
"data_rate_limiter.h",
|
||||||
"deprecated/signal_thread.cc",
|
|
||||||
"deprecated/signal_thread.h",
|
|
||||||
"dscp.h",
|
"dscp.h",
|
||||||
"file_rotating_stream.cc",
|
"file_rotating_stream.cc",
|
||||||
"file_rotating_stream.h",
|
"file_rotating_stream.h",
|
||||||
@ -1005,7 +1000,6 @@ rtc_library("rtc_base") {
|
|||||||
"rtc_certificate.h",
|
"rtc_certificate.h",
|
||||||
"rtc_certificate_generator.cc",
|
"rtc_certificate_generator.cc",
|
||||||
"rtc_certificate_generator.h",
|
"rtc_certificate_generator.h",
|
||||||
"signal_thread.h",
|
|
||||||
"sigslot_repeater.h",
|
"sigslot_repeater.h",
|
||||||
"socket_adapters.cc",
|
"socket_adapters.cc",
|
||||||
"socket_adapters.h",
|
"socket_adapters.h",
|
||||||
@ -1492,7 +1486,6 @@ if (rtc_include_tests) {
|
|||||||
"callback_unittest.cc",
|
"callback_unittest.cc",
|
||||||
"crc32_unittest.cc",
|
"crc32_unittest.cc",
|
||||||
"data_rate_limiter_unittest.cc",
|
"data_rate_limiter_unittest.cc",
|
||||||
"deprecated/signal_thread_unittest.cc",
|
|
||||||
"fake_clock_unittest.cc",
|
"fake_clock_unittest.cc",
|
||||||
"helpers_unittest.cc",
|
"helpers_unittest.cc",
|
||||||
"ip_address_unittest.cc",
|
"ip_address_unittest.cc",
|
||||||
|
@ -1,175 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright 2004 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 "rtc_base/deprecated/signal_thread.h"
|
|
||||||
|
|
||||||
#include <memory>
|
|
||||||
|
|
||||||
#include "rtc_base/checks.h"
|
|
||||||
#include "rtc_base/location.h"
|
|
||||||
#include "rtc_base/null_socket_server.h"
|
|
||||||
#include "rtc_base/socket_server.h"
|
|
||||||
|
|
||||||
namespace rtc {
|
|
||||||
|
|
||||||
///////////////////////////////////////////////////////////////////////////////
|
|
||||||
// SignalThread
|
|
||||||
///////////////////////////////////////////////////////////////////////////////
|
|
||||||
|
|
||||||
DEPRECATED_SignalThread::DEPRECATED_SignalThread()
|
|
||||||
: main_(Thread::Current()), worker_(this), state_(kInit), refcount_(1) {
|
|
||||||
main_->SignalQueueDestroyed.connect(
|
|
||||||
this, &DEPRECATED_SignalThread::OnMainThreadDestroyed);
|
|
||||||
worker_.SetName("SignalThread", this);
|
|
||||||
}
|
|
||||||
|
|
||||||
DEPRECATED_SignalThread::~DEPRECATED_SignalThread() {
|
|
||||||
webrtc::MutexLock lock(&mutex_);
|
|
||||||
RTC_DCHECK(refcount_ == 0);
|
|
||||||
}
|
|
||||||
|
|
||||||
bool DEPRECATED_SignalThread::SetName(const std::string& name,
|
|
||||||
const void* obj) {
|
|
||||||
EnterExit ee(this);
|
|
||||||
RTC_DCHECK(!destroy_called_);
|
|
||||||
RTC_DCHECK(main_->IsCurrent());
|
|
||||||
RTC_DCHECK(kInit == state_);
|
|
||||||
return worker_.SetName(name, obj);
|
|
||||||
}
|
|
||||||
|
|
||||||
void DEPRECATED_SignalThread::Start() {
|
|
||||||
EnterExit ee(this);
|
|
||||||
RTC_DCHECK(!destroy_called_);
|
|
||||||
RTC_DCHECK(main_->IsCurrent());
|
|
||||||
if (kInit == state_ || kComplete == state_) {
|
|
||||||
state_ = kRunning;
|
|
||||||
OnWorkStart();
|
|
||||||
worker_.Start();
|
|
||||||
} else {
|
|
||||||
RTC_NOTREACHED();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void DEPRECATED_SignalThread::Destroy(bool wait) {
|
|
||||||
EnterExit ee(this);
|
|
||||||
// Sometimes the caller can't guarantee which thread will call Destroy, only
|
|
||||||
// that it will be the last thing it does.
|
|
||||||
// RTC_DCHECK(main_->IsCurrent());
|
|
||||||
RTC_DCHECK(!destroy_called_);
|
|
||||||
destroy_called_ = true;
|
|
||||||
if ((kInit == state_) || (kComplete == state_)) {
|
|
||||||
refcount_--;
|
|
||||||
} else if (kRunning == state_ || kReleasing == state_) {
|
|
||||||
state_ = kStopping;
|
|
||||||
// OnWorkStop() must follow Quit(), so that when the thread wakes up due to
|
|
||||||
// OWS(), ContinueWork() will return false.
|
|
||||||
worker_.Quit();
|
|
||||||
OnWorkStop();
|
|
||||||
if (wait) {
|
|
||||||
// Release the thread's lock so that it can return from ::Run.
|
|
||||||
mutex_.Unlock();
|
|
||||||
worker_.Stop();
|
|
||||||
mutex_.Lock();
|
|
||||||
refcount_--;
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
RTC_NOTREACHED();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Disable analysis, to allow calls via SignalWorkDone (which already holds the
|
|
||||||
// lock).
|
|
||||||
// TODO(bugs.webrtc.org/11567): Add a Mutex::AssertHeld, to reenable analysis
|
|
||||||
// and get a runtime check.
|
|
||||||
void DEPRECATED_SignalThread::Release() RTC_NO_THREAD_SAFETY_ANALYSIS {
|
|
||||||
RTC_DCHECK(!destroy_called_);
|
|
||||||
RTC_DCHECK(main_->IsCurrent());
|
|
||||||
if (kComplete == state_) {
|
|
||||||
refcount_--;
|
|
||||||
} else if (kRunning == state_) {
|
|
||||||
state_ = kReleasing;
|
|
||||||
} else {
|
|
||||||
// if (kInit == state_) use Destroy()
|
|
||||||
RTC_NOTREACHED();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
bool DEPRECATED_SignalThread::ContinueWork() {
|
|
||||||
EnterExit ee(this);
|
|
||||||
RTC_DCHECK(!destroy_called_);
|
|
||||||
RTC_DCHECK(worker_.IsCurrent());
|
|
||||||
return worker_.ProcessMessages(0);
|
|
||||||
}
|
|
||||||
|
|
||||||
void DEPRECATED_SignalThread::OnMessage(Message* msg) {
|
|
||||||
EnterExit ee(this);
|
|
||||||
if (ST_MSG_WORKER_DONE == msg->message_id) {
|
|
||||||
RTC_DCHECK(main_->IsCurrent());
|
|
||||||
OnWorkDone();
|
|
||||||
bool do_delete = false;
|
|
||||||
if (kRunning == state_) {
|
|
||||||
state_ = kComplete;
|
|
||||||
} else {
|
|
||||||
do_delete = true;
|
|
||||||
}
|
|
||||||
if (kStopping != state_) {
|
|
||||||
// Before signaling that the work is done, make sure that the worker
|
|
||||||
// thread actually is done. We got here because DoWork() finished and
|
|
||||||
// Run() posted the ST_MSG_WORKER_DONE message. This means the worker
|
|
||||||
// thread is about to go away anyway, but sometimes it doesn't actually
|
|
||||||
// finish before SignalWorkDone is processed, and for a reusable
|
|
||||||
// SignalThread this makes an assert in thread.cc fire.
|
|
||||||
//
|
|
||||||
// Calling Stop() on the worker ensures that the OS thread that underlies
|
|
||||||
// the worker will finish, and will be set to null, enabling us to call
|
|
||||||
// Start() again.
|
|
||||||
worker_.Stop();
|
|
||||||
SignalWorkDone(this);
|
|
||||||
}
|
|
||||||
if (do_delete) {
|
|
||||||
refcount_--;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
DEPRECATED_SignalThread::Worker::Worker(DEPRECATED_SignalThread* parent)
|
|
||||||
: Thread(std::make_unique<NullSocketServer>(), /*do_init=*/false),
|
|
||||||
parent_(parent) {
|
|
||||||
DoInit();
|
|
||||||
}
|
|
||||||
|
|
||||||
DEPRECATED_SignalThread::Worker::~Worker() {
|
|
||||||
Stop();
|
|
||||||
}
|
|
||||||
|
|
||||||
void DEPRECATED_SignalThread::Worker::Run() {
|
|
||||||
parent_->Run();
|
|
||||||
}
|
|
||||||
|
|
||||||
void DEPRECATED_SignalThread::Run() {
|
|
||||||
DoWork();
|
|
||||||
{
|
|
||||||
EnterExit ee(this);
|
|
||||||
if (main_) {
|
|
||||||
main_->Post(RTC_FROM_HERE, this, ST_MSG_WORKER_DONE);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void DEPRECATED_SignalThread::OnMainThreadDestroyed() {
|
|
||||||
EnterExit ee(this);
|
|
||||||
main_ = nullptr;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool DEPRECATED_SignalThread::Worker::IsProcessingMessagesForTesting() {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
} // namespace rtc
|
|
@ -1,178 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright 2004 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 RTC_BASE_DEPRECATED_SIGNAL_THREAD_H_
|
|
||||||
#define RTC_BASE_DEPRECATED_SIGNAL_THREAD_H_
|
|
||||||
|
|
||||||
#include <string>
|
|
||||||
|
|
||||||
#include "rtc_base/checks.h"
|
|
||||||
#include "rtc_base/constructor_magic.h"
|
|
||||||
#include "rtc_base/deprecation.h"
|
|
||||||
#include "rtc_base/message_handler.h"
|
|
||||||
#include "rtc_base/synchronization/mutex.h"
|
|
||||||
#include "rtc_base/third_party/sigslot/sigslot.h"
|
|
||||||
#include "rtc_base/thread.h"
|
|
||||||
#include "rtc_base/thread_annotations.h"
|
|
||||||
|
|
||||||
namespace rtc {
|
|
||||||
|
|
||||||
///////////////////////////////////////////////////////////////////////////////
|
|
||||||
// NOTE: this class has been deprecated. Do not use for new code. New code
|
|
||||||
// should use factilities exposed by api/task_queue/ instead.
|
|
||||||
//
|
|
||||||
// SignalThread - Base class for worker threads. The main thread should call
|
|
||||||
// Start() to begin work, and then follow one of these models:
|
|
||||||
// Normal: Wait for SignalWorkDone, and then call Release to destroy.
|
|
||||||
// Cancellation: Call Release(true), to abort the worker thread.
|
|
||||||
// Fire-and-forget: Call Release(false), which allows the thread to run to
|
|
||||||
// completion, and then self-destruct without further notification.
|
|
||||||
// Periodic tasks: Wait for SignalWorkDone, then eventually call Start()
|
|
||||||
// again to repeat the task. When the instance isn't needed anymore,
|
|
||||||
// call Release. DoWork, OnWorkStart and OnWorkStop are called again,
|
|
||||||
// on a new thread.
|
|
||||||
// The subclass should override DoWork() to perform the background task. By
|
|
||||||
// periodically calling ContinueWork(), it can check for cancellation.
|
|
||||||
// OnWorkStart and OnWorkDone can be overridden to do pre- or post-work
|
|
||||||
// tasks in the context of the main thread.
|
|
||||||
///////////////////////////////////////////////////////////////////////////////
|
|
||||||
|
|
||||||
class DEPRECATED_SignalThread : public sigslot::has_slots<>,
|
|
||||||
protected MessageHandlerAutoCleanup {
|
|
||||||
public:
|
|
||||||
DEPRECATED_SignalThread();
|
|
||||||
|
|
||||||
// Context: Main Thread. Call before Start to change the worker's name.
|
|
||||||
bool SetName(const std::string& name, const void* obj);
|
|
||||||
|
|
||||||
// Context: Main Thread. Call to begin the worker thread.
|
|
||||||
void Start();
|
|
||||||
|
|
||||||
// Context: Main Thread. If the worker thread is not running, deletes the
|
|
||||||
// object immediately. Otherwise, asks the worker thread to abort processing,
|
|
||||||
// and schedules the object to be deleted once the worker exits.
|
|
||||||
// SignalWorkDone will not be signalled. If wait is true, does not return
|
|
||||||
// until the thread is deleted.
|
|
||||||
void Destroy(bool wait);
|
|
||||||
|
|
||||||
// Context: Main Thread. If the worker thread is complete, deletes the
|
|
||||||
// object immediately. Otherwise, schedules the object to be deleted once
|
|
||||||
// the worker thread completes. SignalWorkDone will be signalled.
|
|
||||||
|
|
||||||
// BEWARE: This method must be called with the object's internal lock held, as
|
|
||||||
// if annotated RTC_EXCLUSIVE_LOCKS_REQUIRED(mutex_). Callbacks via OnWorkStop
|
|
||||||
// and SignalWorkDone are already holding the needed lock. It's not annotated,
|
|
||||||
// because it's hard to tell the compiler that functions called via
|
|
||||||
// SignalWorkDone already hold the lock.
|
|
||||||
void Release();
|
|
||||||
|
|
||||||
// Context: Main Thread. Signalled when work is complete.
|
|
||||||
sigslot::signal1<DEPRECATED_SignalThread*> SignalWorkDone;
|
|
||||||
|
|
||||||
enum { ST_MSG_WORKER_DONE, ST_MSG_FIRST_AVAILABLE };
|
|
||||||
|
|
||||||
protected:
|
|
||||||
~DEPRECATED_SignalThread() override;
|
|
||||||
|
|
||||||
Thread* worker() { return &worker_; }
|
|
||||||
|
|
||||||
// Context: Main Thread. Subclass should override to do pre-work setup.
|
|
||||||
virtual void OnWorkStart() {}
|
|
||||||
|
|
||||||
// Context: Worker Thread. Subclass should override to do work.
|
|
||||||
virtual void DoWork() = 0;
|
|
||||||
|
|
||||||
// Context: Worker Thread. Subclass should call periodically to
|
|
||||||
// dispatch messages and determine if the thread should terminate.
|
|
||||||
bool ContinueWork();
|
|
||||||
|
|
||||||
// Context: Worker Thread. Subclass should override when extra work is
|
|
||||||
// needed to abort the worker thread.
|
|
||||||
virtual void OnWorkStop() {}
|
|
||||||
|
|
||||||
// Context: Main Thread. Subclass should override to do post-work cleanup.
|
|
||||||
virtual void OnWorkDone() {}
|
|
||||||
|
|
||||||
// Context: Any Thread. If subclass overrides, be sure to call the base
|
|
||||||
// implementation. Do not use (message_id < ST_MSG_FIRST_AVAILABLE)
|
|
||||||
void OnMessage(Message* msg) override;
|
|
||||||
|
|
||||||
private:
|
|
||||||
enum State {
|
|
||||||
kInit, // Initialized, but not started
|
|
||||||
kRunning, // Started and doing work
|
|
||||||
kReleasing, // Same as running, but to be deleted when work is done
|
|
||||||
kComplete, // Work is done
|
|
||||||
kStopping, // Work is being interrupted
|
|
||||||
};
|
|
||||||
|
|
||||||
class Worker : public Thread {
|
|
||||||
public:
|
|
||||||
explicit Worker(DEPRECATED_SignalThread* parent);
|
|
||||||
|
|
||||||
Worker() = delete;
|
|
||||||
Worker(const Worker&) = delete;
|
|
||||||
Worker& operator=(const Worker&) = delete;
|
|
||||||
|
|
||||||
~Worker() override;
|
|
||||||
void Run() override;
|
|
||||||
bool IsProcessingMessagesForTesting() override;
|
|
||||||
|
|
||||||
private:
|
|
||||||
DEPRECATED_SignalThread* parent_;
|
|
||||||
};
|
|
||||||
|
|
||||||
class RTC_SCOPED_LOCKABLE EnterExit {
|
|
||||||
public:
|
|
||||||
explicit EnterExit(DEPRECATED_SignalThread* t)
|
|
||||||
RTC_EXCLUSIVE_LOCK_FUNCTION(t->mutex_)
|
|
||||||
: t_(t) {
|
|
||||||
t_->mutex_.Lock();
|
|
||||||
// If refcount_ is zero then the object has already been deleted and we
|
|
||||||
// will be double-deleting it in ~EnterExit()! (shouldn't happen)
|
|
||||||
RTC_DCHECK_NE(0, t_->refcount_);
|
|
||||||
++t_->refcount_;
|
|
||||||
}
|
|
||||||
|
|
||||||
EnterExit() = delete;
|
|
||||||
EnterExit(const EnterExit&) = delete;
|
|
||||||
EnterExit& operator=(const EnterExit&) = delete;
|
|
||||||
|
|
||||||
~EnterExit() RTC_UNLOCK_FUNCTION() {
|
|
||||||
bool d = (0 == --t_->refcount_);
|
|
||||||
t_->mutex_.Unlock();
|
|
||||||
if (d)
|
|
||||||
delete t_;
|
|
||||||
}
|
|
||||||
|
|
||||||
private:
|
|
||||||
DEPRECATED_SignalThread* t_;
|
|
||||||
};
|
|
||||||
|
|
||||||
void Run();
|
|
||||||
void OnMainThreadDestroyed();
|
|
||||||
|
|
||||||
Thread* main_;
|
|
||||||
Worker worker_;
|
|
||||||
webrtc::Mutex mutex_;
|
|
||||||
State state_ RTC_GUARDED_BY(mutex_);
|
|
||||||
int refcount_ RTC_GUARDED_BY(mutex_);
|
|
||||||
bool destroy_called_ RTC_GUARDED_BY(mutex_) = false;
|
|
||||||
|
|
||||||
RTC_DISALLOW_COPY_AND_ASSIGN(DEPRECATED_SignalThread);
|
|
||||||
};
|
|
||||||
|
|
||||||
typedef RTC_DEPRECATED DEPRECATED_SignalThread SignalThread;
|
|
||||||
|
|
||||||
///////////////////////////////////////////////////////////////////////////////
|
|
||||||
|
|
||||||
} // namespace rtc
|
|
||||||
|
|
||||||
#endif // RTC_BASE_DEPRECATED_SIGNAL_THREAD_H_
|
|
@ -1,226 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright 2004 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 "rtc_base/signal_thread.h"
|
|
||||||
|
|
||||||
#include <memory>
|
|
||||||
|
|
||||||
#include "rtc_base/constructor_magic.h"
|
|
||||||
#include "rtc_base/gunit.h"
|
|
||||||
#include "rtc_base/null_socket_server.h"
|
|
||||||
#include "rtc_base/synchronization/mutex.h"
|
|
||||||
#include "rtc_base/thread.h"
|
|
||||||
#include "rtc_base/thread_annotations.h"
|
|
||||||
#include "test/gtest.h"
|
|
||||||
|
|
||||||
namespace rtc {
|
|
||||||
namespace {
|
|
||||||
|
|
||||||
// 10 seconds.
|
|
||||||
static const int kTimeout = 10000;
|
|
||||||
|
|
||||||
class SignalThreadTest : public ::testing::Test, public sigslot::has_slots<> {
|
|
||||||
public:
|
|
||||||
class SlowSignalThread : public DEPRECATED_SignalThread {
|
|
||||||
public:
|
|
||||||
explicit SlowSignalThread(SignalThreadTest* harness) : harness_(harness) {}
|
|
||||||
|
|
||||||
~SlowSignalThread() override {
|
|
||||||
EXPECT_EQ(harness_->main_thread_, Thread::Current());
|
|
||||||
++harness_->thread_deleted_;
|
|
||||||
}
|
|
||||||
|
|
||||||
const SignalThreadTest* harness() { return harness_; }
|
|
||||||
|
|
||||||
protected:
|
|
||||||
void OnWorkStart() override {
|
|
||||||
ASSERT_TRUE(harness_ != nullptr);
|
|
||||||
++harness_->thread_started_;
|
|
||||||
EXPECT_EQ(harness_->main_thread_, Thread::Current());
|
|
||||||
EXPECT_FALSE(worker()->RunningForTest()); // not started yet
|
|
||||||
}
|
|
||||||
|
|
||||||
void OnWorkStop() override {
|
|
||||||
++harness_->thread_stopped_;
|
|
||||||
EXPECT_EQ(harness_->main_thread_, Thread::Current());
|
|
||||||
EXPECT_TRUE(worker()->RunningForTest()); // not stopped yet
|
|
||||||
}
|
|
||||||
|
|
||||||
void OnWorkDone() override {
|
|
||||||
++harness_->thread_done_;
|
|
||||||
EXPECT_EQ(harness_->main_thread_, Thread::Current());
|
|
||||||
EXPECT_TRUE(worker()->RunningForTest()); // not stopped yet
|
|
||||||
}
|
|
||||||
|
|
||||||
void DoWork() override {
|
|
||||||
EXPECT_NE(harness_->main_thread_, Thread::Current());
|
|
||||||
EXPECT_EQ(worker(), Thread::Current());
|
|
||||||
Thread::Current()->socketserver()->Wait(250, false);
|
|
||||||
}
|
|
||||||
|
|
||||||
private:
|
|
||||||
SignalThreadTest* harness_;
|
|
||||||
RTC_DISALLOW_COPY_AND_ASSIGN(SlowSignalThread);
|
|
||||||
};
|
|
||||||
|
|
||||||
void OnWorkComplete(rtc::DEPRECATED_SignalThread* thread) {
|
|
||||||
SlowSignalThread* t = static_cast<SlowSignalThread*>(thread);
|
|
||||||
EXPECT_EQ(t->harness(), this);
|
|
||||||
EXPECT_EQ(main_thread_, Thread::Current());
|
|
||||||
|
|
||||||
++thread_completed_;
|
|
||||||
if (!called_release_) {
|
|
||||||
thread->Release();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void SetUp() override {
|
|
||||||
main_thread_ = Thread::Current();
|
|
||||||
thread_ = new SlowSignalThread(this);
|
|
||||||
thread_->SignalWorkDone.connect(this, &SignalThreadTest::OnWorkComplete);
|
|
||||||
called_release_ = false;
|
|
||||||
thread_started_ = 0;
|
|
||||||
thread_done_ = 0;
|
|
||||||
thread_completed_ = 0;
|
|
||||||
thread_stopped_ = 0;
|
|
||||||
thread_deleted_ = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
void ExpectState(int started,
|
|
||||||
int done,
|
|
||||||
int completed,
|
|
||||||
int stopped,
|
|
||||||
int deleted) {
|
|
||||||
EXPECT_EQ(started, thread_started_);
|
|
||||||
EXPECT_EQ(done, thread_done_);
|
|
||||||
EXPECT_EQ(completed, thread_completed_);
|
|
||||||
EXPECT_EQ(stopped, thread_stopped_);
|
|
||||||
EXPECT_EQ(deleted, thread_deleted_);
|
|
||||||
}
|
|
||||||
|
|
||||||
void ExpectStateWait(int started,
|
|
||||||
int done,
|
|
||||||
int completed,
|
|
||||||
int stopped,
|
|
||||||
int deleted,
|
|
||||||
int timeout) {
|
|
||||||
EXPECT_EQ_WAIT(started, thread_started_, timeout);
|
|
||||||
EXPECT_EQ_WAIT(done, thread_done_, timeout);
|
|
||||||
EXPECT_EQ_WAIT(completed, thread_completed_, timeout);
|
|
||||||
EXPECT_EQ_WAIT(stopped, thread_stopped_, timeout);
|
|
||||||
EXPECT_EQ_WAIT(deleted, thread_deleted_, timeout);
|
|
||||||
}
|
|
||||||
|
|
||||||
Thread* main_thread_;
|
|
||||||
SlowSignalThread* thread_;
|
|
||||||
bool called_release_;
|
|
||||||
|
|
||||||
int thread_started_;
|
|
||||||
int thread_done_;
|
|
||||||
int thread_completed_;
|
|
||||||
int thread_stopped_;
|
|
||||||
int thread_deleted_;
|
|
||||||
};
|
|
||||||
|
|
||||||
class OwnerThread : public Thread, public sigslot::has_slots<> {
|
|
||||||
public:
|
|
||||||
explicit OwnerThread(SignalThreadTest* harness)
|
|
||||||
: Thread(std::make_unique<NullSocketServer>()),
|
|
||||||
harness_(harness),
|
|
||||||
has_run_(false) {}
|
|
||||||
|
|
||||||
~OwnerThread() override { Stop(); }
|
|
||||||
|
|
||||||
void Run() override {
|
|
||||||
SignalThreadTest::SlowSignalThread* signal_thread =
|
|
||||||
new SignalThreadTest::SlowSignalThread(harness_);
|
|
||||||
signal_thread->SignalWorkDone.connect(this, &OwnerThread::OnWorkDone);
|
|
||||||
signal_thread->Start();
|
|
||||||
Thread::Current()->socketserver()->Wait(100, false);
|
|
||||||
signal_thread->Release();
|
|
||||||
// Delete |signal_thread|.
|
|
||||||
signal_thread->Destroy(true);
|
|
||||||
{
|
|
||||||
webrtc::MutexLock lock(&mutex_);
|
|
||||||
has_run_ = true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
bool has_run() {
|
|
||||||
webrtc::MutexLock lock(&mutex_);
|
|
||||||
return has_run_;
|
|
||||||
}
|
|
||||||
void OnWorkDone(DEPRECATED_SignalThread* /*signal_thread*/) {
|
|
||||||
FAIL() << " This shouldn't get called.";
|
|
||||||
}
|
|
||||||
|
|
||||||
private:
|
|
||||||
webrtc::Mutex mutex_;
|
|
||||||
SignalThreadTest* harness_;
|
|
||||||
bool has_run_ RTC_GUARDED_BY(mutex_);
|
|
||||||
RTC_DISALLOW_COPY_AND_ASSIGN(OwnerThread);
|
|
||||||
};
|
|
||||||
|
|
||||||
// Test for when the main thread goes away while the
|
|
||||||
// signal thread is still working. This may happen
|
|
||||||
// when shutting down the process.
|
|
||||||
TEST_F(SignalThreadTest, OwnerThreadGoesAway) {
|
|
||||||
// We don't use |thread_| for this test, so destroy it.
|
|
||||||
thread_->Destroy(true);
|
|
||||||
|
|
||||||
{
|
|
||||||
std::unique_ptr<OwnerThread> owner(new OwnerThread(this));
|
|
||||||
main_thread_ = owner.get();
|
|
||||||
owner->Start();
|
|
||||||
while (!owner->has_run()) {
|
|
||||||
Thread::Current()->socketserver()->Wait(10, false);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
// At this point the main thread has gone away.
|
|
||||||
// Give the SignalThread a little time to do its callback,
|
|
||||||
// which will crash if the signal thread doesn't handle
|
|
||||||
// this situation well.
|
|
||||||
Thread::Current()->socketserver()->Wait(500, false);
|
|
||||||
}
|
|
||||||
|
|
||||||
TEST_F(SignalThreadTest, ThreadFinishes) {
|
|
||||||
thread_->Start();
|
|
||||||
ExpectState(1, 0, 0, 0, 0);
|
|
||||||
ExpectStateWait(1, 1, 1, 0, 1, kTimeout);
|
|
||||||
}
|
|
||||||
|
|
||||||
TEST_F(SignalThreadTest, ReleasedThreadFinishes) {
|
|
||||||
thread_->Start();
|
|
||||||
ExpectState(1, 0, 0, 0, 0);
|
|
||||||
thread_->Release();
|
|
||||||
called_release_ = true;
|
|
||||||
ExpectState(1, 0, 0, 0, 0);
|
|
||||||
ExpectStateWait(1, 1, 1, 0, 1, kTimeout);
|
|
||||||
}
|
|
||||||
|
|
||||||
TEST_F(SignalThreadTest, DestroyedThreadCleansUp) {
|
|
||||||
thread_->Start();
|
|
||||||
ExpectState(1, 0, 0, 0, 0);
|
|
||||||
thread_->Destroy(true);
|
|
||||||
ExpectState(1, 0, 0, 1, 1);
|
|
||||||
Thread::Current()->ProcessMessages(0);
|
|
||||||
ExpectState(1, 0, 0, 1, 1);
|
|
||||||
}
|
|
||||||
|
|
||||||
TEST_F(SignalThreadTest, DeferredDestroyedThreadCleansUp) {
|
|
||||||
thread_->Start();
|
|
||||||
ExpectState(1, 0, 0, 0, 0);
|
|
||||||
thread_->Destroy(false);
|
|
||||||
ExpectState(1, 0, 0, 1, 0);
|
|
||||||
ExpectStateWait(1, 1, 0, 1, 1, kTimeout);
|
|
||||||
}
|
|
||||||
|
|
||||||
} // namespace
|
|
||||||
} // namespace rtc
|
|
@ -1,19 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright 2020 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 RTC_BASE_SIGNAL_THREAD_H_
|
|
||||||
#define RTC_BASE_SIGNAL_THREAD_H_
|
|
||||||
|
|
||||||
// The facilities in this file have been deprecated. Please do not use them
|
|
||||||
// in new code. New code should use factilities exposed by api/task_queue/
|
|
||||||
// instead.
|
|
||||||
#include "rtc_base/deprecated/signal_thread.h"
|
|
||||||
|
|
||||||
#endif // RTC_BASE_SIGNAL_THREAD_H_
|
|
@ -31,8 +31,6 @@ char kTSanDefaultSuppressions[] =
|
|||||||
// rtc_unittests
|
// rtc_unittests
|
||||||
// https://code.google.com/p/webrtc/issues/detail?id=2080
|
// https://code.google.com/p/webrtc/issues/detail?id=2080
|
||||||
"race:rtc_base/logging.cc\n"
|
"race:rtc_base/logging.cc\n"
|
||||||
"race:rtc_base/shared_exclusive_lock_unittest.cc\n"
|
|
||||||
"race:rtc_base/signal_thread_unittest.cc\n"
|
|
||||||
|
|
||||||
// rtc_pc_unittests
|
// rtc_pc_unittests
|
||||||
// https://code.google.com/p/webrtc/issues/detail?id=2079
|
// https://code.google.com/p/webrtc/issues/detail?id=2079
|
||||||
|
Reference in New Issue
Block a user