Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(3097)

Unified Diff: base/threading/platform_thread_unittest.cc

Issue 1660273004: base: Set initial thread priority in ThreadFunc. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: cl format and add comment Created 4 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « base/threading/platform_thread_posix.cc ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: base/threading/platform_thread_unittest.cc
diff --git a/base/threading/platform_thread_unittest.cc b/base/threading/platform_thread_unittest.cc
index 52f8d1ba6f31c5158fe6b49e2003c90a844da8f3..1c68dedbdf058e5a17efc55728c2483460fd7e42 100644
--- a/base/threading/platform_thread_unittest.cc
+++ b/base/threading/platform_thread_unittest.cc
@@ -217,7 +217,8 @@ bool IsBumpingPriorityAllowed() {
class ThreadPriorityTestThread : public FunctionTestThread {
public:
- ThreadPriorityTestThread() = default;
+ explicit ThreadPriorityTestThread(ThreadPriority priority)
+ : priority_(priority) {}
~ThreadPriorityTestThread() override = default;
private:
@@ -226,24 +227,13 @@ class ThreadPriorityTestThread : public FunctionTestThread {
EXPECT_EQ(ThreadPriority::NORMAL,
PlatformThread::GetCurrentThreadPriority());
- // Toggle each supported priority on the current thread and confirm it
- // affects it.
- const bool bumping_priority_allowed = IsBumpingPriorityAllowed();
- for (size_t i = 0; i < arraysize(kThreadPriorityTestValues); ++i) {
- SCOPED_TRACE(i);
- if (!bumping_priority_allowed &&
- kThreadPriorityTestValues[i] >
- PlatformThread::GetCurrentThreadPriority()) {
- continue;
- }
-
- // Alter and verify the current thread's priority.
- PlatformThread::SetCurrentThreadPriority(kThreadPriorityTestValues[i]);
- EXPECT_EQ(kThreadPriorityTestValues[i],
- PlatformThread::GetCurrentThreadPriority());
- }
+ // Alter and verify the current thread's priority.
+ PlatformThread::SetCurrentThreadPriority(priority_);
+ EXPECT_EQ(priority_, PlatformThread::GetCurrentThreadPriority());
}
+ const ThreadPriority priority_;
+
DISALLOW_COPY_AND_ASSIGN(ThreadPriorityTestThread);
};
@@ -259,17 +249,33 @@ class ThreadPriorityTestThread : public FunctionTestThread {
// Test changing a created thread's priority (which has different semantics on
// some platforms).
TEST(PlatformThreadTest, MAYBE_ThreadPriorityCurrentThread) {
- ThreadPriorityTestThread thread;
- PlatformThreadHandle handle;
+ const bool bumping_priority_allowed = IsBumpingPriorityAllowed();
+ if (bumping_priority_allowed) {
+ // Bump the priority in order to verify that new threads are started with
+ // normal priority.
+ PlatformThread::SetCurrentThreadPriority(ThreadPriority::DISPLAY);
+ }
- ASSERT_FALSE(thread.IsRunning());
- ASSERT_TRUE(PlatformThread::Create(0, &thread, &handle));
- thread.WaitForTerminationReady();
- ASSERT_TRUE(thread.IsRunning());
+ // Toggle each supported priority on the thread and confirm it affects it.
+ for (size_t i = 0; i < arraysize(kThreadPriorityTestValues); ++i) {
+ if (!bumping_priority_allowed &&
+ kThreadPriorityTestValues[i] >
+ PlatformThread::GetCurrentThreadPriority()) {
+ continue;
+ }
- thread.MarkForTermination();
- PlatformThread::Join(handle);
- ASSERT_FALSE(thread.IsRunning());
+ ThreadPriorityTestThread thread(kThreadPriorityTestValues[i]);
+ PlatformThreadHandle handle;
+
+ ASSERT_FALSE(thread.IsRunning());
+ ASSERT_TRUE(PlatformThread::Create(0, &thread, &handle));
+ thread.WaitForTerminationReady();
+ ASSERT_TRUE(thread.IsRunning());
+
+ thread.MarkForTermination();
+ PlatformThread::Join(handle);
+ ASSERT_FALSE(thread.IsRunning());
+ }
}
} // namespace base
« no previous file with comments | « base/threading/platform_thread_posix.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698