| 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 <sched.h> | 8 #include <sched.h> |
| 9 | 9 |
| 10 #include "base/lazy_instance.h" | 10 #include "base/lazy_instance.h" |
| (...skipping 11 matching lines...) Expand all Loading... |
| 22 | 22 |
| 23 #if defined(OS_LINUX) | 23 #if defined(OS_LINUX) |
| 24 #include <sys/prctl.h> | 24 #include <sys/prctl.h> |
| 25 #include <sys/resource.h> | 25 #include <sys/resource.h> |
| 26 #include <sys/syscall.h> | 26 #include <sys/syscall.h> |
| 27 #include <sys/time.h> | 27 #include <sys/time.h> |
| 28 #include <unistd.h> | 28 #include <unistd.h> |
| 29 #endif | 29 #endif |
| 30 | 30 |
| 31 #if defined(OS_ANDROID) | 31 #if defined(OS_ANDROID) |
| 32 #include <sys/resource.h> |
| 32 #include "base/android/jni_android.h" | 33 #include "base/android/jni_android.h" |
| 33 #endif | 34 #endif |
| 34 | 35 |
| 35 // TODO(bbudge) Use time.h when NaCl toolchain supports _POSIX_TIMERS | 36 // TODO(bbudge) Use time.h when NaCl toolchain supports _POSIX_TIMERS |
| 36 #if defined(OS_NACL) | 37 #if defined(OS_NACL) |
| 37 #include <sys/nacl_syscalls.h> | 38 #include <sys/nacl_syscalls.h> |
| 38 #endif | 39 #endif |
| 39 | 40 |
| 40 namespace base { | 41 namespace base { |
| 41 | 42 |
| 42 #if defined(OS_MACOSX) | 43 #if defined(OS_MACOSX) |
| 43 void InitThreading(); | 44 void InitThreading(); |
| 44 #endif | 45 #endif |
| 45 | 46 |
| 46 namespace { | 47 namespace { |
| 47 | 48 |
| 48 #if !defined(OS_MACOSX) | 49 #if !defined(OS_MACOSX) |
| 49 // Mac name code is in in platform_thread_mac.mm. | 50 // Mac name code is in in platform_thread_mac.mm. |
| 50 LazyInstance<ThreadLocalPointer<char> >::Leaky | 51 LazyInstance<ThreadLocalPointer<char> >::Leaky |
| 51 current_thread_name = LAZY_INSTANCE_INITIALIZER; | 52 current_thread_name = LAZY_INSTANCE_INITIALIZER; |
| 52 #endif | 53 #endif |
| 53 | 54 |
| 54 struct ThreadParams { | 55 struct ThreadParams { |
| 55 PlatformThread::Delegate* delegate; | 56 PlatformThread::Delegate* delegate; |
| 56 bool joinable; | 57 bool joinable; |
| 57 }; | 58 }; |
| 58 | 59 |
| 59 void* ThreadFunc(void* params) { | 60 void* ThreadFunc(void* params) { |
| 61 #if defined(OS_ANDROID) |
| 62 // Threads on linux/android may inherit their priority from the thread |
| 63 // where they were created. This sets all threads to the default. |
| 64 // TODO(epenner): Move thread priorities to base. (crbug.com/170549) |
| 65 if (setpriority(PRIO_PROCESS, PlatformThread::CurrentId(), 0)) |
| 66 DVLOG(1) << "Failed to reset initial thread nice value to zero."; |
| 67 #endif |
| 60 ThreadParams* thread_params = static_cast<ThreadParams*>(params); | 68 ThreadParams* thread_params = static_cast<ThreadParams*>(params); |
| 61 PlatformThread::Delegate* delegate = thread_params->delegate; | 69 PlatformThread::Delegate* delegate = thread_params->delegate; |
| 62 if (!thread_params->joinable) | 70 if (!thread_params->joinable) |
| 63 base::ThreadRestrictions::SetSingletonAllowed(false); | 71 base::ThreadRestrictions::SetSingletonAllowed(false); |
| 64 delete thread_params; | 72 delete thread_params; |
| 65 delegate->ThreadMain(); | 73 delegate->ThreadMain(); |
| 66 #if defined(OS_ANDROID) | 74 #if defined(OS_ANDROID) |
| 67 base::android::DetachFromVM(); | 75 base::android::DetachFromVM(); |
| 68 #endif | 76 #endif |
| 69 return NULL; | 77 return NULL; |
| (...skipping 207 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 277 #if !defined(OS_MACOSX) | 285 #if !defined(OS_MACOSX) |
| 278 // Mac OS X uses lower-level mach APIs. | 286 // Mac OS X uses lower-level mach APIs. |
| 279 | 287 |
| 280 // static | 288 // static |
| 281 void PlatformThread::SetThreadPriority(PlatformThreadHandle, ThreadPriority) { | 289 void PlatformThread::SetThreadPriority(PlatformThreadHandle, ThreadPriority) { |
| 282 // TODO(crogers): Implement, see http://crbug.com/116172 | 290 // TODO(crogers): Implement, see http://crbug.com/116172 |
| 283 } | 291 } |
| 284 #endif | 292 #endif |
| 285 | 293 |
| 286 } // namespace base | 294 } // namespace base |
| OLD | NEW |