| 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 146 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 157 #elif defined(OS_NACL) && defined(__GLIBC__) | 157 #elif defined(OS_NACL) && defined(__GLIBC__) |
| 158 return pthread_self(); | 158 return pthread_self(); |
| 159 #elif defined(OS_NACL) && !defined(__GLIBC__) | 159 #elif defined(OS_NACL) && !defined(__GLIBC__) |
| 160 // Pointers are 32-bits in NaCl. | 160 // Pointers are 32-bits in NaCl. |
| 161 return reinterpret_cast<int32>(pthread_self()); | 161 return reinterpret_cast<int32>(pthread_self()); |
| 162 #elif defined(OS_POSIX) | 162 #elif defined(OS_POSIX) |
| 163 return reinterpret_cast<int64>(pthread_self()); | 163 return reinterpret_cast<int64>(pthread_self()); |
| 164 #endif | 164 #endif |
| 165 } | 165 } |
| 166 | 166 |
| 167 //static | 167 // static |
| 168 PlatformThreadRef PlatformThread::CurrentRef() { |
| 169 return PlatformThreadRef(pthread_self()); |
| 170 } |
| 171 |
| 172 // static |
| 168 PlatformThreadHandle PlatformThread::CurrentHandle() { | 173 PlatformThreadHandle PlatformThread::CurrentHandle() { |
| 169 return PlatformThreadHandle(pthread_self(), CurrentId()); | 174 return PlatformThreadHandle(pthread_self(), CurrentId()); |
| 170 } | 175 } |
| 171 | 176 |
| 172 // static | 177 // static |
| 173 void PlatformThread::YieldCurrentThread() { | 178 void PlatformThread::YieldCurrentThread() { |
| 174 sched_yield(); | 179 sched_yield(); |
| 175 } | 180 } |
| 176 | 181 |
| 177 // static | 182 // static |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 224 // static | 229 // static |
| 225 void PlatformThread::Join(PlatformThreadHandle thread_handle) { | 230 void PlatformThread::Join(PlatformThreadHandle thread_handle) { |
| 226 // Joining another thread may block the current thread for a long time, since | 231 // Joining another thread may block the current thread for a long time, since |
| 227 // the thread referred to by |thread_handle| may still be running long-lived / | 232 // the thread referred to by |thread_handle| may still be running long-lived / |
| 228 // blocking tasks. | 233 // blocking tasks. |
| 229 base::ThreadRestrictions::AssertIOAllowed(); | 234 base::ThreadRestrictions::AssertIOAllowed(); |
| 230 CHECK_EQ(0, pthread_join(thread_handle.handle_, NULL)); | 235 CHECK_EQ(0, pthread_join(thread_handle.handle_, NULL)); |
| 231 } | 236 } |
| 232 | 237 |
| 233 } // namespace base | 238 } // namespace base |
| OLD | NEW |