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

Unified Diff: base/threading/platform_thread_mac.mm

Issue 1620673003: base: Implement GetCurrentThreadPriority. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 11 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 | « no previous file | base/threading/platform_thread_unittest.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: base/threading/platform_thread_mac.mm
diff --git a/base/threading/platform_thread_mac.mm b/base/threading/platform_thread_mac.mm
index df11f852e56c874d281e9ea25c449c7b0194fc77..a5cd9b010058bc601314767a1439d54afa991416 100644
--- a/base/threading/platform_thread_mac.mm
+++ b/base/threading/platform_thread_mac.mm
@@ -15,6 +15,7 @@
#include "base/lazy_instance.h"
#include "base/logging.h"
+#include "base/mac/foundation_util.h"
#include "base/mac/mach_logging.h"
#include "base/threading/thread_id_name_manager.h"
#include "base/tracked_objects.h"
@@ -22,6 +23,10 @@
namespace base {
+namespace {
+NSString* const kThreadPriorityKey = @"kThreadPriorityKey";
Mark Mentovai 2016/02/02 16:38:27 No leading k in the string on the right side. And
erikchen 2016/03/14 21:09:49 Done.
+} // namespace
+
// If Cocoa is to be used on more than one thread, it must know that the
// application is multithreaded. Since it's possible to enter Cocoa code
// from threads created by pthread_thread_create, Cocoa won't necessarily
@@ -164,21 +169,41 @@ void PlatformThread::SetCurrentThreadPriority(ThreadPriority priority) {
switch (priority) {
case ThreadPriority::NORMAL:
+ case ThreadPriority::BACKGROUND:
+ case ThreadPriority::DISPLAY:
+ // Add support for non-NORMAL thread priorities. https://crbug.com/554651
SetPriorityNormal(mach_thread_id);
break;
case ThreadPriority::REALTIME_AUDIO:
SetPriorityRealtimeAudio(mach_thread_id);
break;
- default:
- NOTREACHED() << "Unknown priority.";
- break;
}
+
+ [[[NSThread currentThread] threadDictionary]
+ setObject:@(static_cast<int>(priority))
Mark Mentovai 2016/02/02 16:38:27 OK, but I’d be even happier about this if the ”enu
erikchen 2016/03/14 21:09:49 Done.
+ forKey:kThreadPriorityKey];
}
// static
ThreadPriority PlatformThread::GetCurrentThreadPriority() {
- NOTIMPLEMENTED();
- return ThreadPriority::NORMAL;
+ NSNumber* priority = base::mac::ObjCCast<NSNumber>([[[NSThread currentThread]
+ threadDictionary] objectForKey:kThreadPriorityKey]);
+
+ if (!priority)
+ return ThreadPriority::NORMAL;
+
+ ThreadPriority thread_priority =
+ static_cast<ThreadPriority>(priority.intValue);
+ switch (thread_priority) {
+ case ThreadPriority::BACKGROUND:
+ case ThreadPriority::NORMAL:
+ case ThreadPriority::DISPLAY:
+ case ThreadPriority::REALTIME_AUDIO:
+ return thread_priority;
+ default:
+ NOTREACHED() << "Unknown priority.";
+ return ThreadPriority::NORMAL;
+ }
}
size_t GetDefaultThreadStackSize(const pthread_attr_t& attributes) {
« no previous file with comments | « no previous file | base/threading/platform_thread_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698