| 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 "base/threading/platform_thread.h" | 5 #include "base/threading/platform_thread.h" |
| 6 | 6 |
| 7 #include <errno.h> | 7 #include <errno.h> |
| 8 #include <pthread.h> | 8 #include <pthread.h> |
| 9 #include <sched.h> | 9 #include <sched.h> |
| 10 #include <stddef.h> | 10 #include <stddef.h> |
| (...skipping 11 matching lines...) Expand all Loading... |
| 22 | 22 |
| 23 #if defined(OS_LINUX) | 23 #if defined(OS_LINUX) |
| 24 #include <sys/syscall.h> | 24 #include <sys/syscall.h> |
| 25 #elif defined(OS_ANDROID) | 25 #elif defined(OS_ANDROID) |
| 26 #include <sys/types.h> | 26 #include <sys/types.h> |
| 27 #endif | 27 #endif |
| 28 | 28 |
| 29 namespace base { | 29 namespace base { |
| 30 | 30 |
| 31 void InitThreading(); | 31 void InitThreading(); |
| 32 void InitOnThread(); | |
| 33 void TerminateOnThread(); | 32 void TerminateOnThread(); |
| 34 size_t GetDefaultThreadStackSize(const pthread_attr_t& attributes); | 33 size_t GetDefaultThreadStackSize(const pthread_attr_t& attributes); |
| 35 | 34 |
| 36 namespace { | 35 namespace { |
| 37 | 36 |
| 38 struct ThreadParams { | 37 struct ThreadParams { |
| 39 ThreadParams() | 38 ThreadParams() |
| 40 : delegate(NULL), joinable(false), priority(ThreadPriority::NORMAL) {} | 39 : delegate(NULL), joinable(false), priority(ThreadPriority::NORMAL) {} |
| 41 | 40 |
| 42 PlatformThread::Delegate* delegate; | 41 PlatformThread::Delegate* delegate; |
| 43 bool joinable; | 42 bool joinable; |
| 44 ThreadPriority priority; | 43 ThreadPriority priority; |
| 45 }; | 44 }; |
| 46 | 45 |
| 47 void* ThreadFunc(void* params) { | 46 void* ThreadFunc(void* params) { |
| 48 base::InitOnThread(); | |
| 49 | |
| 50 PlatformThread::Delegate* delegate = nullptr; | 47 PlatformThread::Delegate* delegate = nullptr; |
| 51 | 48 |
| 52 { | 49 { |
| 53 scoped_ptr<ThreadParams> thread_params(static_cast<ThreadParams*>(params)); | 50 scoped_ptr<ThreadParams> thread_params(static_cast<ThreadParams*>(params)); |
| 54 | 51 |
| 55 delegate = thread_params->delegate; | 52 delegate = thread_params->delegate; |
| 56 if (!thread_params->joinable) | 53 if (!thread_params->joinable) |
| 57 base::ThreadRestrictions::SetSingletonAllowed(false); | 54 base::ThreadRestrictions::SetSingletonAllowed(false); |
| 58 | 55 |
| 59 if (thread_params->priority != ThreadPriority::NORMAL) | 56 #if !defined(OS_NACL) |
| 60 PlatformThread::SetCurrentThreadPriority(thread_params->priority); | 57 // Threads on linux/android may inherit their priority from the thread |
| 58 // where they were created. This explicitly sets the priority of all new |
| 59 // threads. |
| 60 PlatformThread::SetCurrentThreadPriority(thread_params->priority); |
| 61 #endif |
| 61 } | 62 } |
| 62 | 63 |
| 63 ThreadIdNameManager::GetInstance()->RegisterThread( | 64 ThreadIdNameManager::GetInstance()->RegisterThread( |
| 64 PlatformThread::CurrentHandle().platform_handle(), | 65 PlatformThread::CurrentHandle().platform_handle(), |
| 65 PlatformThread::CurrentId()); | 66 PlatformThread::CurrentId()); |
| 66 | 67 |
| 67 delegate->ThreadMain(); | 68 delegate->ThreadMain(); |
| 68 | 69 |
| 69 ThreadIdNameManager::GetInstance()->RemoveName( | 70 ThreadIdNameManager::GetInstance()->RemoveName( |
| 70 PlatformThread::CurrentHandle().platform_handle(), | 71 PlatformThread::CurrentHandle().platform_handle(), |
| (...skipping 183 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 254 return ThreadPriority::NORMAL; | 255 return ThreadPriority::NORMAL; |
| 255 } | 256 } |
| 256 | 257 |
| 257 return internal::NiceValueToThreadPriority(nice_value); | 258 return internal::NiceValueToThreadPriority(nice_value); |
| 258 #endif // !defined(OS_NACL) | 259 #endif // !defined(OS_NACL) |
| 259 } | 260 } |
| 260 | 261 |
| 261 #endif // !defined(OS_MACOSX) | 262 #endif // !defined(OS_MACOSX) |
| 262 | 263 |
| 263 } // namespace base | 264 } // namespace base |
| OLD | NEW |