Chromium Code Reviews| 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) { |