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:
@ -594,21 +594,6 @@ TEST_F(PosixSignalDeliveryTest, SignalDuringWait) {
|
|||||||
EXPECT_TRUE(ExpectNone());
|
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
|
// 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).
|
// signal to (since it's not guaranteed to be the one that Wait() runs on).
|
||||||
// TODO(webrtc:7864): Fails on real iOS devices
|
// 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
|
// thread. Our implementation should safely handle it and dispatch
|
||||||
// RecordSignal() on this thread.
|
// RecordSignal() on this thread.
|
||||||
std::unique_ptr<Thread> thread(Thread::CreateWithSocketServer());
|
std::unique_ptr<Thread> thread(Thread::CreateWithSocketServer());
|
||||||
std::unique_ptr<RaiseSigTermRunnable> runnable(new RaiseSigTermRunnable());
|
thread->Start();
|
||||||
thread->Start(runnable.get());
|
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(ss_->Wait(1500, true));
|
||||||
EXPECT_TRUE(ExpectSignal(SIGTERM));
|
EXPECT_TRUE(ExpectSignal(SIGTERM));
|
||||||
EXPECT_EQ(Thread::Current(), signaled_thread_);
|
EXPECT_EQ(Thread::Current(), signaled_thread_);
|
||||||
|
@ -229,7 +229,7 @@ bool Thread::SetName(const std::string& name, const void* obj) {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Thread::Start(Runnable* runnable) {
|
bool Thread::Start() {
|
||||||
RTC_DCHECK(!IsRunning());
|
RTC_DCHECK(!IsRunning());
|
||||||
|
|
||||||
if (IsRunning())
|
if (IsRunning())
|
||||||
@ -243,11 +243,8 @@ bool Thread::Start(Runnable* runnable) {
|
|||||||
|
|
||||||
owned_ = true;
|
owned_ = true;
|
||||||
|
|
||||||
ThreadInit* init = new ThreadInit;
|
|
||||||
init->thread = this;
|
|
||||||
init->runnable = runnable;
|
|
||||||
#if defined(WEBRTC_WIN)
|
#if defined(WEBRTC_WIN)
|
||||||
thread_ = CreateThread(nullptr, 0, PreRun, init, 0, &thread_id_);
|
thread_ = CreateThread(nullptr, 0, PreRun, this, 0, &thread_id_);
|
||||||
if (!thread_) {
|
if (!thread_) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@ -255,7 +252,7 @@ bool Thread::Start(Runnable* runnable) {
|
|||||||
pthread_attr_t attr;
|
pthread_attr_t attr;
|
||||||
pthread_attr_init(&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) {
|
if (0 != error_code) {
|
||||||
RTC_LOG(LS_ERROR) << "Unable to create pthread, error " << error_code;
|
RTC_LOG(LS_ERROR) << "Unable to create pthread, error " << error_code;
|
||||||
thread_ = 0;
|
thread_ = 0;
|
||||||
@ -334,19 +331,15 @@ DWORD WINAPI Thread::PreRun(LPVOID pv) {
|
|||||||
#else
|
#else
|
||||||
void* Thread::PreRun(void* pv) {
|
void* Thread::PreRun(void* pv) {
|
||||||
#endif
|
#endif
|
||||||
ThreadInit* init = static_cast<ThreadInit*>(pv);
|
Thread* thread = static_cast<Thread*>(pv);
|
||||||
ThreadManager::Instance()->SetCurrentThread(init->thread);
|
ThreadManager::Instance()->SetCurrentThread(thread);
|
||||||
rtc::SetCurrentThreadName(init->thread->name_.c_str());
|
rtc::SetCurrentThreadName(thread->name_.c_str());
|
||||||
#if defined(WEBRTC_MAC)
|
#if defined(WEBRTC_MAC)
|
||||||
ScopedAutoReleasePool pool;
|
ScopedAutoReleasePool pool;
|
||||||
#endif
|
#endif
|
||||||
if (init->runnable) {
|
thread->Run();
|
||||||
init->runnable->Run(init->thread);
|
|
||||||
} else {
|
|
||||||
init->thread->Run();
|
|
||||||
}
|
|
||||||
ThreadManager::Instance()->SetCurrentThread(nullptr);
|
ThreadManager::Instance()->SetCurrentThread(nullptr);
|
||||||
delete init;
|
|
||||||
#ifdef WEBRTC_WIN
|
#ifdef WEBRTC_WIN
|
||||||
return 0;
|
return 0;
|
||||||
#else
|
#else
|
||||||
|
@ -129,18 +129,6 @@ struct _SendMessage {
|
|||||||
bool* ready;
|
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().
|
// WARNING! SUBCLASSES MUST CALL Stop() IN THEIR DESTRUCTORS! See ~Thread().
|
||||||
|
|
||||||
class RTC_LOCKABLE Thread : public MessageQueue {
|
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);
|
bool SetName(const std::string& name, const void* obj);
|
||||||
|
|
||||||
// Starts the execution of the thread.
|
// Starts the execution of the thread.
|
||||||
bool Start(Runnable* runnable = nullptr);
|
bool Start();
|
||||||
|
|
||||||
// Tells the thread to stop and waits until it is joined.
|
// Tells the thread to stop and waits until it is joined.
|
||||||
// Never call Stop on the current thread. Instead use the inherited Quit
|
// 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;
|
friend class ScopedDisallowBlockingCalls;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
struct ThreadInit {
|
|
||||||
Thread* thread;
|
|
||||||
Runnable* runnable;
|
|
||||||
};
|
|
||||||
|
|
||||||
// Sets the per-thread allow-blocking-calls flag and returns the previous
|
// Sets the per-thread allow-blocking-calls flag and returns the previous
|
||||||
// value. Must be called on this thread.
|
// value. Must be called on this thread.
|
||||||
bool SetAllowBlockingCalls(bool allow);
|
bool SetAllowBlockingCalls(bool allow);
|
||||||
|
Reference in New Issue
Block a user