Prepare for deletion of the NO_MAIN_THREAD_WRAPPING preprocessor define

This is a partial reland of
https://webrtc-review.googlesource.com/c/src/+/39680,
including only the (hopefully) non-problematic parts of it, but
postponing actual deletion of automatic thread wrapping.

Bug: webrtc:9714
Change-Id: I9b79dd073f0e945cbb62f3b54cff05eaaea9b06c
Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/141664
Reviewed-by: Karl Wiberg <kwiberg@webrtc.org>
Commit-Queue: Niels Moller <nisse@webrtc.org>
Cr-Commit-Position: refs/heads/master@{#28265}
This commit is contained in:
Niels Möller 2019-06-12 11:30:59 +02:00 committed by Commit Bot
parent 50dd80b96f
commit 5a8f860a01
5 changed files with 21 additions and 24 deletions

View file

@ -121,20 +121,6 @@ TEST_F(MessageQueueTest, DiposeHandlerWithPostedMessagePending) {
EXPECT_TRUE(deleted); EXPECT_TRUE(deleted);
} }
struct UnwrapMainThreadScope {
UnwrapMainThreadScope() : rewrap_(Thread::Current() != nullptr) {
if (rewrap_)
ThreadManager::Instance()->UnwrapCurrentThread();
}
~UnwrapMainThreadScope() {
if (rewrap_)
ThreadManager::Instance()->WrapCurrentThread();
}
private:
bool rewrap_;
};
// Ensure that ProcessAllMessageQueues does its essential function; process // Ensure that ProcessAllMessageQueues does its essential function; process
// all messages (both delayed and non delayed) up until the current time, on // all messages (both delayed and non delayed) up until the current time, on
// all registered message queues. // all registered message queues.

View file

@ -567,8 +567,11 @@ bool Thread::IsRunning() {
AutoThread::AutoThread() AutoThread::AutoThread()
: Thread(SocketServer::CreateDefault(), /*do_init=*/false) { : Thread(SocketServer::CreateDefault(), /*do_init=*/false) {
DoInit();
if (!ThreadManager::Instance()->CurrentThread()) { if (!ThreadManager::Instance()->CurrentThread()) {
// DoInit registers with MessageQueueManager. Do that only if we intend to
// be rtc::Thread::Current(), otherwise ProcessAllMessageQueuesInternal will
// post a message to a queue that no running thread is serving.
DoInit();
ThreadManager::Instance()->SetCurrentThread(this); ThreadManager::Instance()->SetCurrentThread(this);
} }
} }

View file

@ -267,15 +267,18 @@ TEST(ThreadTest, Names) {
TEST(ThreadTest, Wrap) { TEST(ThreadTest, Wrap) {
Thread* current_thread = Thread::Current(); Thread* current_thread = Thread::Current();
current_thread->UnwrapCurrent(); ThreadManager::Instance()->SetCurrentThread(nullptr);
CustomThread* cthread = new CustomThread();
EXPECT_TRUE(cthread->WrapCurrent()); {
EXPECT_TRUE(cthread->RunningForTest()); CustomThread cthread;
EXPECT_FALSE(cthread->IsOwned()); EXPECT_TRUE(cthread.WrapCurrent());
cthread->UnwrapCurrent(); EXPECT_EQ(&cthread, Thread::Current());
EXPECT_FALSE(cthread->RunningForTest()); EXPECT_TRUE(cthread.RunningForTest());
delete cthread; EXPECT_FALSE(cthread.IsOwned());
current_thread->WrapCurrent(); cthread.UnwrapCurrent();
EXPECT_FALSE(cthread.RunningForTest());
}
ThreadManager::Instance()->SetCurrentThread(current_thread);
} }
TEST(ThreadTest, Invoke) { TEST(ThreadTest, Invoke) {

View file

@ -1125,6 +1125,7 @@ if (is_ios || is_mac) {
":peerconnectionfactory_base_objc", ":peerconnectionfactory_base_objc",
":sdk_unittests_bundle_data", ":sdk_unittests_bundle_data",
":sdk_unittests_sources", ":sdk_unittests_sources",
"../rtc_base",
"//test:test_support", "//test:test_support",
] ]
ldflags = [ "-all_load" ] ldflags = [ "-all_load" ]
@ -1143,6 +1144,7 @@ if (is_ios || is_mac) {
deps = [ deps = [
":framework_objc+link", ":framework_objc+link",
":ios_framework_bundle", ":ios_framework_bundle",
"../rtc_base",
"//test:test_support", "//test:test_support",
] ]
} }

View file

@ -10,11 +10,14 @@
#import <Foundation/Foundation.h> #import <Foundation/Foundation.h>
#import <UIKit/UIKit.h> #import <UIKit/UIKit.h>
#include "rtc_base/thread.h"
#include "test/ios/coverage_util_ios.h" #include "test/ios/coverage_util_ios.h"
int main(int argc, char* argv[]) { int main(int argc, char* argv[]) {
rtc::test::ConfigureCoverageReportPath(); rtc::test::ConfigureCoverageReportPath();
rtc::AutoThread main_thread;
@autoreleasepool { @autoreleasepool {
return UIApplicationMain(argc, argv, nil, nil); return UIApplicationMain(argc, argv, nil, nil);
} }