OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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) | 5 #if defined(OS_WIN) |
6 #include <windows.h> | 6 #include <windows.h> |
7 #include <process.h> | 7 #include <process.h> |
8 #endif | 8 #endif |
9 | 9 |
10 #include "base/threading/simple_thread.h" | 10 #include "base/threading/simple_thread.h" |
11 #include "base/threading/thread_local_storage.h" | 11 #include "base/threading/thread_local_storage.h" |
12 #include "testing/gtest/include/gtest/gtest.h" | 12 #include "testing/gtest/include/gtest/gtest.h" |
13 | 13 |
14 #if defined(OS_WIN) | 14 #if defined(OS_WIN) |
15 // Ignore warnings about ptr->int conversions that we use when | 15 // Ignore warnings about ptr->int conversions that we use when |
16 // storing ints into ThreadLocalStorage. | 16 // storing ints into ThreadLocalStorage. |
17 #pragma warning(disable : 4311 4312) | 17 #pragma warning(disable : 4311 4312) |
18 #endif | 18 #endif |
19 | 19 |
20 namespace base { | 20 namespace base { |
21 | 21 |
22 namespace { | 22 namespace { |
23 | 23 |
24 const int kInitialTlsValue = 0x5555; | 24 const int kInitialTlsValue = 0x5555; |
25 const int kFinalTlsValue = 0x7777; | 25 const int kFinalTlsValue = 0x7777; |
26 // How many times must a destructor be called before we really are done. | 26 // How many times must a destructor be called before we really are done. |
27 const int kNumberDestructorCallRepetitions = 3; | 27 const int kNumberDestructorCallRepetitions = 3; |
28 | 28 |
29 static ThreadLocalStorage::Slot tls_slot(LINKER_INITIALIZED); | 29 static ThreadLocalStorage::StaticSlot tls_slot = TLS_INITIALIZER; |
30 | 30 |
31 class ThreadLocalStorageRunner : public DelegateSimpleThread::Delegate { | 31 class ThreadLocalStorageRunner : public DelegateSimpleThread::Delegate { |
32 public: | 32 public: |
33 explicit ThreadLocalStorageRunner(int* tls_value_ptr) | 33 explicit ThreadLocalStorageRunner(int* tls_value_ptr) |
34 : tls_value_ptr_(tls_value_ptr) {} | 34 : tls_value_ptr_(tls_value_ptr) {} |
35 | 35 |
36 virtual ~ThreadLocalStorageRunner() {} | 36 virtual ~ThreadLocalStorageRunner() {} |
37 | 37 |
38 virtual void Run() { | 38 virtual void Run() { |
39 *tls_value_ptr_ = kInitialTlsValue; | 39 *tls_value_ptr_ = kInitialTlsValue; |
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
105 delete threads[index]; | 105 delete threads[index]; |
106 delete thread_delegates[index]; | 106 delete thread_delegates[index]; |
107 | 107 |
108 // Verify that the destructor was called and that we reset. | 108 // Verify that the destructor was called and that we reset. |
109 EXPECT_EQ(values[index], kFinalTlsValue); | 109 EXPECT_EQ(values[index], kFinalTlsValue); |
110 } | 110 } |
111 tls_slot.Free(); // Stop doing callbacks to cleanup threads. | 111 tls_slot.Free(); // Stop doing callbacks to cleanup threads. |
112 } | 112 } |
113 | 113 |
114 } // namespace base | 114 } // namespace base |
OLD | NEW |