| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "base/logging.h" | 5 #include "base/logging.h" |
| 6 #include "base/threading/simple_thread.h" | 6 #include "base/threading/simple_thread.h" |
| 7 #include "base/threading/thread_local.h" | 7 #include "base/threading/thread_local.h" |
| 8 #include "base/synchronization/waitable_event.h" | 8 #include "base/synchronization/waitable_event.h" |
| 9 #include "testing/gtest/include/gtest/gtest.h" | 9 #include "testing/gtest/include/gtest/gtest.h" |
| 10 | 10 |
| (...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 75 base::DelegateSimpleThreadPool tp1("ThreadLocalTest tp1", 1); | 75 base::DelegateSimpleThreadPool tp1("ThreadLocalTest tp1", 1); |
| 76 base::DelegateSimpleThreadPool tp2("ThreadLocalTest tp1", 1); | 76 base::DelegateSimpleThreadPool tp2("ThreadLocalTest tp1", 1); |
| 77 tp1.Start(); | 77 tp1.Start(); |
| 78 tp2.Start(); | 78 tp2.Start(); |
| 79 | 79 |
| 80 base::ThreadLocalPointer<char> tlp; | 80 base::ThreadLocalPointer<char> tlp; |
| 81 | 81 |
| 82 static char* const kBogusPointer = reinterpret_cast<char*>(0x1234); | 82 static char* const kBogusPointer = reinterpret_cast<char*>(0x1234); |
| 83 | 83 |
| 84 char* tls_val; | 84 char* tls_val; |
| 85 base::WaitableEvent done(true, false); | 85 base::WaitableEvent done(WaitableEvent::ResetPolicy::MANUAL, |
| 86 WaitableEvent::InitialState::NOT_SIGNALED); |
| 86 | 87 |
| 87 GetThreadLocal getter(&tlp, &done); | 88 GetThreadLocal getter(&tlp, &done); |
| 88 getter.set_ptr(&tls_val); | 89 getter.set_ptr(&tls_val); |
| 89 | 90 |
| 90 // Check that both threads defaulted to NULL. | 91 // Check that both threads defaulted to NULL. |
| 91 tls_val = kBogusPointer; | 92 tls_val = kBogusPointer; |
| 92 done.Reset(); | 93 done.Reset(); |
| 93 tp1.AddWork(&getter); | 94 tp1.AddWork(&getter); |
| 94 done.Wait(); | 95 done.Wait(); |
| 95 EXPECT_EQ(static_cast<char*>(NULL), tls_val); | 96 EXPECT_EQ(static_cast<char*>(NULL), tls_val); |
| (...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 159 } | 160 } |
| 160 | 161 |
| 161 // Our slot should have been freed, we're all reset. | 162 // Our slot should have been freed, we're all reset. |
| 162 { | 163 { |
| 163 base::ThreadLocalBoolean tlb; | 164 base::ThreadLocalBoolean tlb; |
| 164 EXPECT_FALSE(tlb.Get()); | 165 EXPECT_FALSE(tlb.Get()); |
| 165 } | 166 } |
| 166 } | 167 } |
| 167 | 168 |
| 168 } // namespace base | 169 } // namespace base |
| OLD | NEW |