OLD | NEW |
1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2008 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/simple_thread.h" | 6 #include "base/simple_thread.h" |
7 #include "base/thread_local.h" | 7 #include "base/thread_local.h" |
8 #include "base/waitable_event.h" | 8 #include "base/waitable_event.h" |
9 #include "testing/gtest/include/gtest/gtest.h" | 9 #include "testing/gtest/include/gtest/gtest.h" |
10 | 10 |
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
78 base::WaitableEvent done(true, false); | 78 base::WaitableEvent done(true, false); |
79 | 79 |
80 GetThreadLocal getter(&tlp, &done); | 80 GetThreadLocal getter(&tlp, &done); |
81 getter.set_ptr(&tls_val); | 81 getter.set_ptr(&tls_val); |
82 | 82 |
83 // Check that both threads defaulted to NULL. | 83 // Check that both threads defaulted to NULL. |
84 tls_val = kBogusPointer; | 84 tls_val = kBogusPointer; |
85 done.Reset(); | 85 done.Reset(); |
86 tp1.AddWork(&getter); | 86 tp1.AddWork(&getter); |
87 done.Wait(); | 87 done.Wait(); |
88 EXPECT_EQ(NULL, tls_val); | 88 EXPECT_EQ(static_cast<ThreadLocalTesterBase*>(NULL), tls_val); |
89 | 89 |
90 tls_val = kBogusPointer; | 90 tls_val = kBogusPointer; |
91 done.Reset(); | 91 done.Reset(); |
92 tp2.AddWork(&getter); | 92 tp2.AddWork(&getter); |
93 done.Wait(); | 93 done.Wait(); |
94 EXPECT_EQ(NULL, tls_val); | 94 EXPECT_EQ(static_cast<ThreadLocalTesterBase*>(NULL), tls_val); |
95 | 95 |
96 | 96 |
97 SetThreadLocal setter(&tlp, &done); | 97 SetThreadLocal setter(&tlp, &done); |
98 setter.set_value(kBogusPointer); | 98 setter.set_value(kBogusPointer); |
99 | 99 |
100 // Have thread 1 set their pointer value to kBogusPointer. | 100 // Have thread 1 set their pointer value to kBogusPointer. |
101 done.Reset(); | 101 done.Reset(); |
102 tp1.AddWork(&setter); | 102 tp1.AddWork(&setter); |
103 done.Wait(); | 103 done.Wait(); |
104 | 104 |
105 tls_val = NULL; | 105 tls_val = NULL; |
106 done.Reset(); | 106 done.Reset(); |
107 tp1.AddWork(&getter); | 107 tp1.AddWork(&getter); |
108 done.Wait(); | 108 done.Wait(); |
109 EXPECT_EQ(kBogusPointer, tls_val); | 109 EXPECT_EQ(kBogusPointer, tls_val); |
110 | 110 |
111 // Make sure thread 2 is still NULL | 111 // Make sure thread 2 is still NULL |
112 tls_val = kBogusPointer; | 112 tls_val = kBogusPointer; |
113 done.Reset(); | 113 done.Reset(); |
114 tp2.AddWork(&getter); | 114 tp2.AddWork(&getter); |
115 done.Wait(); | 115 done.Wait(); |
116 EXPECT_EQ(NULL, tls_val); | 116 EXPECT_EQ(static_cast<ThreadLocalTesterBase*>(NULL), tls_val); |
117 | 117 |
118 // Set thread 2 to kBogusPointer + 1. | 118 // Set thread 2 to kBogusPointer + 1. |
119 setter.set_value(kBogusPointer + 1); | 119 setter.set_value(kBogusPointer + 1); |
120 | 120 |
121 done.Reset(); | 121 done.Reset(); |
122 tp2.AddWork(&setter); | 122 tp2.AddWork(&setter); |
123 done.Wait(); | 123 done.Wait(); |
124 | 124 |
125 tls_val = NULL; | 125 tls_val = NULL; |
126 done.Reset(); | 126 done.Reset(); |
(...skipping 23 matching lines...) Expand all Loading... |
150 tlb.Set(true); | 150 tlb.Set(true); |
151 EXPECT_EQ(true, tlb.Get()); | 151 EXPECT_EQ(true, tlb.Get()); |
152 } | 152 } |
153 | 153 |
154 // Our slot should have been freed, we're all reset. | 154 // Our slot should have been freed, we're all reset. |
155 { | 155 { |
156 base::ThreadLocalBoolean tlb; | 156 base::ThreadLocalBoolean tlb; |
157 EXPECT_EQ(false, tlb.Get()); | 157 EXPECT_EQ(false, tlb.Get()); |
158 } | 158 } |
159 } | 159 } |
OLD | NEW |