| 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 <sys/resource.h> | 10 #include <sys/resource.h> |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 56 | 56 |
| 57 PlatformThread::Delegate* delegate = thread_params->delegate; | 57 PlatformThread::Delegate* delegate = thread_params->delegate; |
| 58 if (!thread_params->joinable) | 58 if (!thread_params->joinable) |
| 59 base::ThreadRestrictions::SetSingletonAllowed(false); | 59 base::ThreadRestrictions::SetSingletonAllowed(false); |
| 60 | 60 |
| 61 if (thread_params->priority != ThreadPriority::NORMAL) | 61 if (thread_params->priority != ThreadPriority::NORMAL) |
| 62 PlatformThread::SetCurrentThreadPriority(thread_params->priority); | 62 PlatformThread::SetCurrentThreadPriority(thread_params->priority); |
| 63 | 63 |
| 64 // Stash the id in the handle so the calling thread has a complete | 64 // Stash the id in the handle so the calling thread has a complete |
| 65 // handle, and unblock the parent thread. | 65 // handle, and unblock the parent thread. |
| 66 *(thread_params->handle) = PlatformThreadHandle(pthread_self(), | 66 *(thread_params->handle) = PlatformThreadHandle(pthread_self()); |
| 67 PlatformThread::CurrentId()); | |
| 68 thread_params->handle_set.Signal(); | 67 thread_params->handle_set.Signal(); |
| 69 | 68 |
| 70 ThreadIdNameManager::GetInstance()->RegisterThread( | 69 ThreadIdNameManager::GetInstance()->RegisterThread( |
| 71 PlatformThread::CurrentHandle().platform_handle(), | 70 PlatformThread::CurrentHandle().platform_handle(), |
| 72 PlatformThread::CurrentId()); | 71 PlatformThread::CurrentId()); |
| 73 | 72 |
| 74 delegate->ThreadMain(); | 73 delegate->ThreadMain(); |
| 75 | 74 |
| 76 ThreadIdNameManager::GetInstance()->RemoveName( | 75 ThreadIdNameManager::GetInstance()->RemoveName( |
| 77 PlatformThread::CurrentHandle().platform_handle(), | 76 PlatformThread::CurrentHandle().platform_handle(), |
| (...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 158 #endif | 157 #endif |
| 159 } | 158 } |
| 160 | 159 |
| 161 // static | 160 // static |
| 162 PlatformThreadRef PlatformThread::CurrentRef() { | 161 PlatformThreadRef PlatformThread::CurrentRef() { |
| 163 return PlatformThreadRef(pthread_self()); | 162 return PlatformThreadRef(pthread_self()); |
| 164 } | 163 } |
| 165 | 164 |
| 166 // static | 165 // static |
| 167 PlatformThreadHandle PlatformThread::CurrentHandle() { | 166 PlatformThreadHandle PlatformThread::CurrentHandle() { |
| 168 return PlatformThreadHandle(pthread_self(), CurrentId()); | 167 return PlatformThreadHandle(pthread_self()); |
| 169 } | 168 } |
| 170 | 169 |
| 171 // static | 170 // static |
| 172 void PlatformThread::YieldCurrentThread() { | 171 void PlatformThread::YieldCurrentThread() { |
| 173 sched_yield(); | 172 sched_yield(); |
| 174 } | 173 } |
| 175 | 174 |
| 176 // static | 175 // static |
| 177 void PlatformThread::Sleep(TimeDelta duration) { | 176 void PlatformThread::Sleep(TimeDelta duration) { |
| 178 struct timespec sleep_time, remaining; | 177 struct timespec sleep_time, remaining; |
| (...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 277 return ThreadPriority::NORMAL; | 276 return ThreadPriority::NORMAL; |
| 278 } | 277 } |
| 279 | 278 |
| 280 return internal::NiceValueToThreadPriority(nice_value); | 279 return internal::NiceValueToThreadPriority(nice_value); |
| 281 #endif // !defined(OS_NACL) | 280 #endif // !defined(OS_NACL) |
| 282 } | 281 } |
| 283 | 282 |
| 284 #endif // !defined(OS_MACOSX) | 283 #endif // !defined(OS_MACOSX) |
| 285 | 284 |
| 286 } // namespace base | 285 } // namespace base |
| OLD | NEW |