Delete optional Runnable argument to rtc::Thread::Start

Intended to simplify later changes to thread shutdown logic.

Bug: webrtc:10648
Change-Id: I61ba240c0f4b73a0bc6af6a3471804ecb434c41f
Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/137510
Commit-Queue: Niels Moller <nisse@webrtc.org>
Reviewed-by: Karl Wiberg <kwiberg@webrtc.org>
Cr-Commit-Position: refs/heads/master@{#28219}
This commit is contained in:
Niels Möller
2019-06-11 09:24:14 +02:00
committed by Commit Bot
parent 240b893fd2
commit d2e5013858
3 changed files with 22 additions and 50 deletions

View File

@ -594,21 +594,6 @@ TEST_F(PosixSignalDeliveryTest, SignalDuringWait) {
EXPECT_TRUE(ExpectNone());
}
class RaiseSigTermRunnable : public Runnable {
void Run(Thread* thread) override {
thread->socketserver()->Wait(1000, false);
// Allow SIGTERM. This will be the only thread with it not masked so it will
// be delivered to us.
sigset_t mask;
sigemptyset(&mask);
pthread_sigmask(SIG_SETMASK, &mask, nullptr);
// Raise it.
raise(SIGTERM);
}
};
// Test that it works no matter what thread the kernel chooses to give the
// signal to (since it's not guaranteed to be the one that Wait() runs on).
// TODO(webrtc:7864): Fails on real iOS devices
@ -628,8 +613,19 @@ TEST_F(PosixSignalDeliveryTest, DISABLED_SignalOnDifferentThread) {
// thread. Our implementation should safely handle it and dispatch
// RecordSignal() on this thread.
std::unique_ptr<Thread> thread(Thread::CreateWithSocketServer());
std::unique_ptr<RaiseSigTermRunnable> runnable(new RaiseSigTermRunnable());
thread->Start(runnable.get());
thread->Start();
thread->PostTask(RTC_FROM_HERE, [&thread]() {
thread->socketserver()->Wait(1000, false);
// Allow SIGTERM. This will be the only thread with it not masked so it will
// be delivered to us.
sigset_t mask;
sigemptyset(&mask);
pthread_sigmask(SIG_SETMASK, &mask, nullptr);
// Raise it.
raise(SIGTERM);
});
EXPECT_TRUE(ss_->Wait(1500, true));
EXPECT_TRUE(ExpectSignal(SIGTERM));
EXPECT_EQ(Thread::Current(), signaled_thread_);

View File

@ -229,7 +229,7 @@ bool Thread::SetName(const std::string& name, const void* obj) {
return true;
}
bool Thread::Start(Runnable* runnable) {
bool Thread::Start() {
RTC_DCHECK(!IsRunning());
if (IsRunning())
@ -243,11 +243,8 @@ bool Thread::Start(Runnable* runnable) {
owned_ = true;
ThreadInit* init = new ThreadInit;
init->thread = this;
init->runnable = runnable;
#if defined(WEBRTC_WIN)
thread_ = CreateThread(nullptr, 0, PreRun, init, 0, &thread_id_);
thread_ = CreateThread(nullptr, 0, PreRun, this, 0, &thread_id_);
if (!thread_) {
return false;
}
@ -255,7 +252,7 @@ bool Thread::Start(Runnable* runnable) {
pthread_attr_t attr;
pthread_attr_init(&attr);
int error_code = pthread_create(&thread_, &attr, PreRun, init);
int error_code = pthread_create(&thread_, &attr, PreRun, this);
if (0 != error_code) {
RTC_LOG(LS_ERROR) << "Unable to create pthread, error " << error_code;
thread_ = 0;
@ -334,19 +331,15 @@ DWORD WINAPI Thread::PreRun(LPVOID pv) {
#else
void* Thread::PreRun(void* pv) {
#endif
ThreadInit* init = static_cast<ThreadInit*>(pv);
ThreadManager::Instance()->SetCurrentThread(init->thread);
rtc::SetCurrentThreadName(init->thread->name_.c_str());
Thread* thread = static_cast<Thread*>(pv);
ThreadManager::Instance()->SetCurrentThread(thread);
rtc::SetCurrentThreadName(thread->name_.c_str());
#if defined(WEBRTC_MAC)
ScopedAutoReleasePool pool;
#endif
if (init->runnable) {
init->runnable->Run(init->thread);
} else {
init->thread->Run();
}
thread->Run();
ThreadManager::Instance()->SetCurrentThread(nullptr);
delete init;
#ifdef WEBRTC_WIN
return 0;
#else

View File

@ -129,18 +129,6 @@ struct _SendMessage {
bool* ready;
};
class Runnable {
public:
virtual ~Runnable() {}
virtual void Run(Thread* thread) = 0;
protected:
Runnable() {}
private:
RTC_DISALLOW_COPY_AND_ASSIGN(Runnable);
};
// WARNING! SUBCLASSES MUST CALL Stop() IN THEIR DESTRUCTORS! See ~Thread().
class RTC_LOCKABLE Thread : public MessageQueue {
@ -193,7 +181,7 @@ class RTC_LOCKABLE Thread : public MessageQueue {
bool SetName(const std::string& name, const void* obj);
// Starts the execution of the thread.
bool Start(Runnable* runnable = nullptr);
bool Start();
// Tells the thread to stop and waits until it is joined.
// Never call Stop on the current thread. Instead use the inherited Quit
@ -335,11 +323,6 @@ class RTC_LOCKABLE Thread : public MessageQueue {
friend class ScopedDisallowBlockingCalls;
private:
struct ThreadInit {
Thread* thread;
Runnable* runnable;
};
// Sets the per-thread allow-blocking-calls flag and returns the previous
// value. Must be called on this thread.
bool SetAllowBlockingCalls(bool allow);