| OLD | NEW |
| 1 // Copyright 2014 the V8 project authors. All rights reserved. | 1 // Copyright 2014 the V8 project 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 "src/base/platform/platform.h" | 5 #include "src/base/platform/platform.h" |
| 6 | 6 |
| 7 #if V8_OS_POSIX | 7 #if V8_OS_POSIX |
| 8 #include <unistd.h> // NOLINT | 8 #include <unistd.h> // NOLINT |
| 9 #endif | 9 #endif |
| 10 | 10 |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 49 thread.Start(); | 49 thread.Start(); |
| 50 thread.Join(); | 50 thread.Join(); |
| 51 } | 51 } |
| 52 | 52 |
| 53 | 53 |
| 54 namespace { | 54 namespace { |
| 55 | 55 |
| 56 class ThreadLocalStorageTest : public Thread, public ::testing::Test { | 56 class ThreadLocalStorageTest : public Thread, public ::testing::Test { |
| 57 public: | 57 public: |
| 58 ThreadLocalStorageTest() : Thread(Options("ThreadLocalStorageTest")) { | 58 ThreadLocalStorageTest() : Thread(Options("ThreadLocalStorageTest")) { |
| 59 for (size_t i = 0; i < ARRAY_SIZE(keys_); ++i) { | 59 for (size_t i = 0; i < arraysize(keys_); ++i) { |
| 60 keys_[i] = Thread::CreateThreadLocalKey(); | 60 keys_[i] = Thread::CreateThreadLocalKey(); |
| 61 } | 61 } |
| 62 } | 62 } |
| 63 ~ThreadLocalStorageTest() { | 63 ~ThreadLocalStorageTest() { |
| 64 for (size_t i = 0; i < ARRAY_SIZE(keys_); ++i) { | 64 for (size_t i = 0; i < arraysize(keys_); ++i) { |
| 65 Thread::DeleteThreadLocalKey(keys_[i]); | 65 Thread::DeleteThreadLocalKey(keys_[i]); |
| 66 } | 66 } |
| 67 } | 67 } |
| 68 | 68 |
| 69 virtual void Run() V8_FINAL V8_OVERRIDE { | 69 virtual void Run() V8_FINAL V8_OVERRIDE { |
| 70 for (size_t i = 0; i < ARRAY_SIZE(keys_); i++) { | 70 for (size_t i = 0; i < arraysize(keys_); i++) { |
| 71 CHECK(!Thread::HasThreadLocal(keys_[i])); | 71 CHECK(!Thread::HasThreadLocal(keys_[i])); |
| 72 } | 72 } |
| 73 for (size_t i = 0; i < ARRAY_SIZE(keys_); i++) { | 73 for (size_t i = 0; i < arraysize(keys_); i++) { |
| 74 Thread::SetThreadLocal(keys_[i], GetValue(i)); | 74 Thread::SetThreadLocal(keys_[i], GetValue(i)); |
| 75 } | 75 } |
| 76 for (size_t i = 0; i < ARRAY_SIZE(keys_); i++) { | 76 for (size_t i = 0; i < arraysize(keys_); i++) { |
| 77 CHECK(Thread::HasThreadLocal(keys_[i])); | 77 CHECK(Thread::HasThreadLocal(keys_[i])); |
| 78 } | 78 } |
| 79 for (size_t i = 0; i < ARRAY_SIZE(keys_); i++) { | 79 for (size_t i = 0; i < arraysize(keys_); i++) { |
| 80 CHECK_EQ(GetValue(i), Thread::GetThreadLocal(keys_[i])); | 80 CHECK_EQ(GetValue(i), Thread::GetThreadLocal(keys_[i])); |
| 81 CHECK_EQ(GetValue(i), Thread::GetExistingThreadLocal(keys_[i])); | 81 CHECK_EQ(GetValue(i), Thread::GetExistingThreadLocal(keys_[i])); |
| 82 } | 82 } |
| 83 for (size_t i = 0; i < ARRAY_SIZE(keys_); i++) { | 83 for (size_t i = 0; i < arraysize(keys_); i++) { |
| 84 Thread::SetThreadLocal(keys_[i], GetValue(ARRAY_SIZE(keys_) - i - 1)); | 84 Thread::SetThreadLocal(keys_[i], GetValue(arraysize(keys_) - i - 1)); |
| 85 } | 85 } |
| 86 for (size_t i = 0; i < ARRAY_SIZE(keys_); i++) { | 86 for (size_t i = 0; i < arraysize(keys_); i++) { |
| 87 CHECK(Thread::HasThreadLocal(keys_[i])); | 87 CHECK(Thread::HasThreadLocal(keys_[i])); |
| 88 } | 88 } |
| 89 for (size_t i = 0; i < ARRAY_SIZE(keys_); i++) { | 89 for (size_t i = 0; i < arraysize(keys_); i++) { |
| 90 CHECK_EQ(GetValue(ARRAY_SIZE(keys_) - i - 1), | 90 CHECK_EQ(GetValue(arraysize(keys_) - i - 1), |
| 91 Thread::GetThreadLocal(keys_[i])); | 91 Thread::GetThreadLocal(keys_[i])); |
| 92 CHECK_EQ(GetValue(ARRAY_SIZE(keys_) - i - 1), | 92 CHECK_EQ(GetValue(arraysize(keys_) - i - 1), |
| 93 Thread::GetExistingThreadLocal(keys_[i])); | 93 Thread::GetExistingThreadLocal(keys_[i])); |
| 94 } | 94 } |
| 95 } | 95 } |
| 96 | 96 |
| 97 private: | 97 private: |
| 98 static void* GetValue(size_t x) { | 98 static void* GetValue(size_t x) { |
| 99 return reinterpret_cast<void*>(static_cast<uintptr_t>(x + 1)); | 99 return reinterpret_cast<void*>(static_cast<uintptr_t>(x + 1)); |
| 100 } | 100 } |
| 101 | 101 |
| 102 Thread::LocalStorageKey keys_[256]; | 102 Thread::LocalStorageKey keys_[256]; |
| 103 }; | 103 }; |
| 104 | 104 |
| 105 } | 105 } |
| 106 | 106 |
| 107 | 107 |
| 108 TEST_F(ThreadLocalStorageTest, DoTest) { | 108 TEST_F(ThreadLocalStorageTest, DoTest) { |
| 109 Run(); | 109 Run(); |
| 110 Start(); | 110 Start(); |
| 111 Join(); | 111 Join(); |
| 112 } | 112 } |
| 113 | 113 |
| 114 } // namespace base | 114 } // namespace base |
| 115 } // namespace v8 | 115 } // namespace v8 |
| OLD | NEW |