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 #if defined(OS_WIN) | |
6 #include <windows.h> | |
7 #include <process.h> | |
8 #endif | |
9 | |
10 #include "base/threading/simple_thread.h" | 5 #include "base/threading/simple_thread.h" |
11 #include "base/threading/thread_local_storage.h" | 6 #include "base/threading/thread_local_storage.h" |
12 #include "testing/gtest/include/gtest/gtest.h" | 7 #include "testing/gtest/include/gtest/gtest.h" |
13 | 8 |
14 #if defined(OS_WIN) | |
15 // Ignore warnings about ptr->int conversions that we use when | |
16 // storing ints into ThreadLocalStorage. | |
17 #pragma warning(disable : 4311 4312) | |
18 #endif | |
19 | |
20 namespace base { | 9 namespace base { |
21 | 10 |
22 namespace { | 11 namespace { |
23 | 12 |
24 const int kInitialTlsValue = 0x5555; | 13 const int kInitialTlsValue = 0x5555; |
25 const int kFinalTlsValue = 0x7777; | 14 const int kFinalTlsValue = 0x7777; |
26 // How many times must a destructor be called before we really are done. | 15 // How many times must a destructor be called before we really are done. |
27 const int kNumberDestructorCallRepetitions = 3; | 16 const int kNumberDestructorCallRepetitions = 3; |
28 | 17 |
29 static ThreadLocalStorage::StaticSlot tls_slot = TLS_INITIALIZER; | 18 static ThreadLocalStorage::StaticSlot tls_slot = TLS_INITIALIZER; |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
72 | 61 |
73 } // namespace | 62 } // namespace |
74 | 63 |
75 TEST(ThreadLocalStorageTest, Basics) { | 64 TEST(ThreadLocalStorageTest, Basics) { |
76 ThreadLocalStorage::Slot slot; | 65 ThreadLocalStorage::Slot slot; |
77 slot.Set(reinterpret_cast<void*>(123)); | 66 slot.Set(reinterpret_cast<void*>(123)); |
78 int value = reinterpret_cast<intptr_t>(slot.Get()); | 67 int value = reinterpret_cast<intptr_t>(slot.Get()); |
79 EXPECT_EQ(value, 123); | 68 EXPECT_EQ(value, 123); |
80 } | 69 } |
81 | 70 |
82 #if defined(THREAD_SANITIZER) || \ | 71 #if defined(THREAD_SANITIZER) |
83 (defined(OS_WIN) && defined(ARCH_CPU_X86_64) && !defined(NDEBUG)) | |
84 // Do not run the test under ThreadSanitizer. Because this test iterates its | 72 // Do not run the test under ThreadSanitizer. Because this test iterates its |
85 // own TSD destructor for the maximum possible number of times, TSan can't jump | 73 // own TSD destructor for the maximum possible number of times, TSan can't jump |
86 // in after the last destructor invocation, therefore the destructor remains | 74 // in after the last destructor invocation, therefore the destructor remains |
87 // unsynchronized with the following users of the same TSD slot. This results | 75 // unsynchronized with the following users of the same TSD slot. This results |
88 // in race reports between the destructor and functions in other tests. | 76 // in race reports between the destructor and functions in other tests. |
89 // | 77 // |
90 // It is disabled on Win x64 with incremental linking (i.e. "Debug") pending | 78 // It is disabled on Win x64 with incremental linking (i.e. "Debug") pending |
91 // resolution of http://crbug.com/251251. | 79 // resolution of http://crbug.com/251251. |
92 #define MAYBE_TLSDestructors DISABLED_TLSDestructors | 80 #define MAYBE_TLSDestructors DISABLED_TLSDestructors |
93 #else | 81 #else |
(...skipping 25 matching lines...) Expand all Loading... |
119 delete threads[index]; | 107 delete threads[index]; |
120 delete thread_delegates[index]; | 108 delete thread_delegates[index]; |
121 | 109 |
122 // Verify that the destructor was called and that we reset. | 110 // Verify that the destructor was called and that we reset. |
123 EXPECT_EQ(values[index], kFinalTlsValue); | 111 EXPECT_EQ(values[index], kFinalTlsValue); |
124 } | 112 } |
125 tls_slot.Free(); // Stop doing callbacks to cleanup threads. | 113 tls_slot.Free(); // Stop doing callbacks to cleanup threads. |
126 } | 114 } |
127 | 115 |
128 } // namespace base | 116 } // namespace base |
OLD | NEW |