| 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 12 matching lines...) Expand all Loading... |
| 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 <sys/resource.h> |
| 33 #include "base/android/jni_android.h" | 33 #include "base/android/thread_utils.h" |
| 34 #include "jni/ThreadUtils_jni.h" |
| 34 #endif | 35 #endif |
| 35 | 36 |
| 36 // TODO(bbudge) Use time.h when NaCl toolchain supports _POSIX_TIMERS | 37 // TODO(bbudge) Use time.h when NaCl toolchain supports _POSIX_TIMERS |
| 37 #if defined(OS_NACL) | 38 #if defined(OS_NACL) |
| 38 #include <sys/nacl_syscalls.h> | 39 #include <sys/nacl_syscalls.h> |
| 39 #endif | 40 #endif |
| 40 | 41 |
| 41 namespace base { | 42 namespace base { |
| 42 | 43 |
| 43 #if defined(OS_MACOSX) | 44 #if defined(OS_MACOSX) |
| (...skipping 219 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 263 | 264 |
| 264 // static | 265 // static |
| 265 void PlatformThread::Join(PlatformThreadHandle thread_handle) { | 266 void PlatformThread::Join(PlatformThreadHandle thread_handle) { |
| 266 // Joining another thread may block the current thread for a long time, since | 267 // Joining another thread may block the current thread for a long time, since |
| 267 // the thread referred to by |thread_handle| may still be running long-lived / | 268 // the thread referred to by |thread_handle| may still be running long-lived / |
| 268 // blocking tasks. | 269 // blocking tasks. |
| 269 base::ThreadRestrictions::AssertIOAllowed(); | 270 base::ThreadRestrictions::AssertIOAllowed(); |
| 270 pthread_join(thread_handle, NULL); | 271 pthread_join(thread_handle, NULL); |
| 271 } | 272 } |
| 272 | 273 |
| 273 #if !defined(OS_MACOSX) | 274 #if !defined(OS_MACOSX) && !defined(OS_ANDROID) |
| 274 // Mac OS X uses lower-level mach APIs. | 275 // Mac OS X uses lower-level mach APIs and Android uses Java APIs. |
| 275 | |
| 276 // static | 276 // static |
| 277 void PlatformThread::SetThreadPriority(PlatformThreadHandle, ThreadPriority) { | 277 void PlatformThread::SetThreadPriority(PlatformThreadHandle, ThreadPriority) { |
| 278 // TODO(crogers): Implement, see http://crbug.com/116172 | 278 // TODO(crogers): Implement, see http://crbug.com/116172 |
| 279 } | 279 } |
| 280 #endif | 280 #endif |
| 281 | 281 |
| 282 #if defined(OS_ANDROID) |
| 283 bool RegisterThreadUtils(JNIEnv* env) { |
| 284 return RegisterNativesImpl(env); |
| 285 } |
| 286 |
| 287 void PlatformThread::SetThreadPriority(PlatformThreadHandle, |
| 288 ThreadPriority priority) { |
| 289 if (priority == kThreadPriority_RealtimeAudio) { |
| 290 JNIEnv* env = base::android::AttachCurrentThread(); |
| 291 Java_ThreadUtils_setThreadPriorityAudio(env, PlatformThread::CurrentId()); |
| 292 } else { |
| 293 NOTREACHED() << "Unknown thread priority."; |
| 294 } |
| 295 } |
| 296 #endif // defined(OS_ANDROID) |
| 297 |
| 282 } // namespace base | 298 } // namespace base |
| OLD | NEW |