From 2b1a73547e27f226c678eedc4afd4dbb425ae7ac Mon Sep 17 00:00:00 2001 From: Harvey Tuch Date: Tue, 23 Jan 2018 11:24:35 -0500 Subject: [PATCH 1/2] tls: initialize main thread dispatcher explicitly. Waiting for first dispatch loop is too late for ADS use with Google gRPC client. Testing: ADS integration test with Google gRPC client, existing tests. Risk Level: Low Signed-off-by: Harvey Tuch --- source/common/thread_local/thread_local_impl.cc | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/source/common/thread_local/thread_local_impl.cc b/source/common/thread_local/thread_local_impl.cc index 25799078db1dc..e1805e3e85f37 100644 --- a/source/common/thread_local/thread_local_impl.cc +++ b/source/common/thread_local/thread_local_impl.cc @@ -48,12 +48,12 @@ void InstanceImpl::registerThread(Event::Dispatcher& dispatcher, bool main_threa if (main_thread) { main_thread_dispatcher_ = &dispatcher; + thread_local_data_.dispatcher_ = &dispatcher; } else { ASSERT(!containsReference(registered_threads_, dispatcher)); registered_threads_.push_back(dispatcher); + dispatcher.post([&dispatcher] { thread_local_data_.dispatcher_ = &dispatcher; }); } - - dispatcher.post([&dispatcher] { thread_local_data_.dispatcher_ = &dispatcher; }); } void InstanceImpl::removeSlot(SlotImpl& slot) { From 8f3574ec66eac07fd94e37e1af0d9342efac787f Mon Sep 17 00:00:00 2001 From: Harvey Tuch Date: Tue, 23 Jan 2018 11:59:54 -0500 Subject: [PATCH 2/2] Fix TLS test. Signed-off-by: Harvey Tuch --- test/common/thread_local/thread_local_impl_test.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/common/thread_local/thread_local_impl_test.cc b/test/common/thread_local/thread_local_impl_test.cc index bf93ccd641cb1..8641bb6508b53 100644 --- a/test/common/thread_local/thread_local_impl_test.cc +++ b/test/common/thread_local/thread_local_impl_test.cc @@ -23,8 +23,8 @@ class TestThreadLocalObject : public ThreadLocalObject { class ThreadLocalInstanceImplTest : public testing::Test { public: ThreadLocalInstanceImplTest() { - EXPECT_CALL(main_dispatcher_, post(_)); tls_.registerThread(main_dispatcher_, true); + EXPECT_EQ(&main_dispatcher_, &tls_.dispatcher()); EXPECT_CALL(thread_dispatcher_, post(_)); tls_.registerThread(thread_dispatcher_, false); }