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}
diff --git a/rtc_base/physical_socket_server_unittest.cc b/rtc_base/physical_socket_server_unittest.cc
index 611fb18..3987a59 100644
--- a/rtc_base/physical_socket_server_unittest.cc
+++ b/rtc_base/physical_socket_server_unittest.cc
@@ -594,21 +594,6 @@
   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 @@
   // 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_);
diff --git a/rtc_base/thread.cc b/rtc_base/thread.cc
index be0d15d..5c4749d 100644
--- a/rtc_base/thread.cc
+++ b/rtc_base/thread.cc
@@ -229,7 +229,7 @@
   return true;
 }
 
-bool Thread::Start(Runnable* runnable) {
+bool Thread::Start() {
   RTC_DCHECK(!IsRunning());
 
   if (IsRunning())
@@ -243,11 +243,8 @@
 
   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 @@
   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 @@
 #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
diff --git a/rtc_base/thread.h b/rtc_base/thread.h
index 2b4d020..7d29fbf 100644
--- a/rtc_base/thread.h
+++ b/rtc_base/thread.h
@@ -129,18 +129,6 @@
   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 @@
   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 @@
   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);