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 <stddef.h> | 5 #include <stddef.h> |
6 | 6 |
7 #include "base/compiler_specific.h" | 7 #include "base/compiler_specific.h" |
8 #include "base/macros.h" | 8 #include "base/macros.h" |
9 #include "base/synchronization/waitable_event.h" | 9 #include "base/synchronization/waitable_event.h" |
10 #include "base/threading/platform_thread.h" | 10 #include "base/threading/platform_thread.h" |
(...skipping 242 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
253 const ThreadPriority priority_; | 253 const ThreadPriority priority_; |
254 | 254 |
255 DISALLOW_COPY_AND_ASSIGN(ThreadPriorityTestThread); | 255 DISALLOW_COPY_AND_ASSIGN(ThreadPriorityTestThread); |
256 }; | 256 }; |
257 | 257 |
258 } // namespace | 258 } // namespace |
259 | 259 |
260 // Test changing a created thread's priority (which has different semantics on | 260 // Test changing a created thread's priority (which has different semantics on |
261 // some platforms). | 261 // some platforms). |
262 TEST(PlatformThreadTest, ThreadPriorityCurrentThread) { | 262 TEST(PlatformThreadTest, ThreadPriorityCurrentThread) { |
263 const bool increase_priority_allowed = | 263 const bool increased_priority_allowed = |
264 PlatformThread::CanIncreaseCurrentThreadPriority(); | 264 PlatformThread::CanIncreaseCurrentThreadPriority(); |
265 if (increase_priority_allowed) { | 265 if (increased_priority_allowed) { |
266 // Bump the priority in order to verify that new threads are started with | 266 // Bump the priority in order to verify that new threads are started with |
267 // normal priority. | 267 // normal priority. |
268 PlatformThread::SetCurrentThreadPriority(ThreadPriority::DISPLAY); | 268 PlatformThread::SetCurrentThreadPriority(ThreadPriority::DISPLAY); |
269 } | 269 } |
270 | 270 |
271 // Toggle each supported priority on the thread and confirm it affects it. | 271 // Toggle each supported priority on the thread and confirm it affects it. |
272 for (size_t i = 0; i < arraysize(kThreadPriorityTestValues); ++i) { | 272 for (size_t i = 0; i < arraysize(kThreadPriorityTestValues); ++i) { |
273 if (!increase_priority_allowed && | 273 if (!increased_priority_allowed && |
274 kThreadPriorityTestValues[i] > | 274 kThreadPriorityTestValues[i] > |
275 PlatformThread::GetCurrentThreadPriority()) { | 275 PlatformThread::GetCurrentThreadPriority()) { |
276 continue; | 276 continue; |
277 } | 277 } |
278 | 278 |
279 ThreadPriorityTestThread thread(kThreadPriorityTestValues[i]); | 279 ThreadPriorityTestThread thread(kThreadPriorityTestValues[i]); |
280 PlatformThreadHandle handle; | 280 PlatformThreadHandle handle; |
281 | 281 |
282 ASSERT_FALSE(thread.IsRunning()); | 282 ASSERT_FALSE(thread.IsRunning()); |
283 ASSERT_TRUE(PlatformThread::Create(0, &thread, &handle)); | 283 ASSERT_TRUE(PlatformThread::Create(0, &thread, &handle)); |
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
344 EXPECT_EQ(ThreadPriority::DISPLAY, | 344 EXPECT_EQ(ThreadPriority::DISPLAY, |
345 NiceValueToThreadPriority(kRealtimeAudioNiceValue + 1)); | 345 NiceValueToThreadPriority(kRealtimeAudioNiceValue + 1)); |
346 EXPECT_EQ(ThreadPriority::REALTIME_AUDIO, | 346 EXPECT_EQ(ThreadPriority::REALTIME_AUDIO, |
347 NiceValueToThreadPriority(kRealtimeAudioNiceValue)); | 347 NiceValueToThreadPriority(kRealtimeAudioNiceValue)); |
348 EXPECT_EQ(ThreadPriority::REALTIME_AUDIO, | 348 EXPECT_EQ(ThreadPriority::REALTIME_AUDIO, |
349 NiceValueToThreadPriority(kLowestNiceValue)); | 349 NiceValueToThreadPriority(kLowestNiceValue)); |
350 } | 350 } |
351 #endif | 351 #endif |
352 | 352 |
353 } // namespace base | 353 } // namespace base |
OLD | NEW |