Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(197)

Side by Side Diff: base/threading/platform_thread_posix.cc

Issue 1207823004: PlatformThreadHandle: remove public id() interface (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: (rebase to show diff from 1193303002) Created 5 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
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(), PlatformThread::CurrentId());
72 PlatformThread::CurrentId());
73 71
74 delegate->ThreadMain(); 72 delegate->ThreadMain();
75 73
76 ThreadIdNameManager::GetInstance()->RemoveName( 74 ThreadIdNameManager::GetInstance()->RemoveName(
77 PlatformThread::CurrentHandle().platform_handle(), 75 PlatformThread::CurrentHandle(), PlatformThread::CurrentId());
78 PlatformThread::CurrentId());
79 76
80 base::TerminateOnThread(); 77 base::TerminateOnThread();
81 return NULL; 78 return NULL;
82 } 79 }
83 80
84 bool CreateThread(size_t stack_size, bool joinable, 81 bool CreateThread(size_t stack_size, bool joinable,
85 PlatformThread::Delegate* delegate, 82 PlatformThread::Delegate* delegate,
86 PlatformThreadHandle* thread_handle, 83 PlatformThreadHandle* thread_handle,
87 ThreadPriority priority) { 84 ThreadPriority priority) {
88 base::InitThreading(); 85 base::InitThreading();
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
122 errno = err; 119 errno = err;
123 PLOG(ERROR) << "pthread_create"; 120 PLOG(ERROR) << "pthread_create";
124 } 121 }
125 122
126 pthread_attr_destroy(&attributes); 123 pthread_attr_destroy(&attributes);
127 124
128 // Don't let this call complete until the thread id 125 // Don't let this call complete until the thread id
129 // is set in the handle. 126 // is set in the handle.
130 if (success) 127 if (success)
131 params.handle_set.Wait(); 128 params.handle_set.Wait();
132 CHECK_EQ(handle, thread_handle->platform_handle()); 129 CHECK(thread_handle->is_equal(PlatformThreadHandle(handle)));
133 130
134 return success; 131 return success;
135 } 132 }
136 133
137 } // namespace 134 } // namespace
138 135
139 // static 136 // static
140 PlatformThreadId PlatformThread::CurrentId() { 137 PlatformThreadId PlatformThread::CurrentId() {
141 // Pthreads doesn't have the concept of a thread ID, so we have to reach down 138 // Pthreads doesn't have the concept of a thread ID, so we have to reach down
142 // into the kernel. 139 // into the kernel.
(...skipping 15 matching lines...) Expand all
158 #endif 155 #endif
159 } 156 }
160 157
161 // static 158 // static
162 PlatformThreadRef PlatformThread::CurrentRef() { 159 PlatformThreadRef PlatformThread::CurrentRef() {
163 return PlatformThreadRef(pthread_self()); 160 return PlatformThreadRef(pthread_self());
164 } 161 }
165 162
166 // static 163 // static
167 PlatformThreadHandle PlatformThread::CurrentHandle() { 164 PlatformThreadHandle PlatformThread::CurrentHandle() {
168 return PlatformThreadHandle(pthread_self(), CurrentId()); 165 return PlatformThreadHandle(pthread_self());
169 } 166 }
170 167
171 // static 168 // static
172 void PlatformThread::YieldCurrentThread() { 169 void PlatformThread::YieldCurrentThread() {
173 sched_yield(); 170 sched_yield();
174 } 171 }
175 172
176 // static 173 // static
177 void PlatformThread::Sleep(TimeDelta duration) { 174 void PlatformThread::Sleep(TimeDelta duration) {
178 struct timespec sleep_time, remaining; 175 struct timespec sleep_time, remaining;
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
219 delegate, &unused, ThreadPriority::NORMAL); 216 delegate, &unused, ThreadPriority::NORMAL);
220 return result; 217 return result;
221 } 218 }
222 219
223 // static 220 // static
224 void PlatformThread::Join(PlatformThreadHandle thread_handle) { 221 void PlatformThread::Join(PlatformThreadHandle thread_handle) {
225 // Joining another thread may block the current thread for a long time, since 222 // Joining another thread may block the current thread for a long time, since
226 // the thread referred to by |thread_handle| may still be running long-lived / 223 // the thread referred to by |thread_handle| may still be running long-lived /
227 // blocking tasks. 224 // blocking tasks.
228 base::ThreadRestrictions::AssertIOAllowed(); 225 base::ThreadRestrictions::AssertIOAllowed();
229 CHECK_EQ(0, pthread_join(thread_handle.platform_handle(), NULL)); 226 CHECK_EQ(0, pthread_join(thread_handle.handle_, NULL));
230 } 227 }
231 228
232 // Mac has its own Set/GetCurrentThreadPriority() implementations. 229 // Mac has its own Set/GetCurrentThreadPriority() implementations.
233 #if !defined(OS_MACOSX) 230 #if !defined(OS_MACOSX)
234 231
235 // static 232 // static
236 void PlatformThread::SetCurrentThreadPriority(ThreadPriority priority) { 233 void PlatformThread::SetCurrentThreadPriority(ThreadPriority priority) {
237 #if defined(OS_NACL) 234 #if defined(OS_NACL)
238 NOTIMPLEMENTED(); 235 NOTIMPLEMENTED();
239 #else 236 #else
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
277 return ThreadPriority::NORMAL; 274 return ThreadPriority::NORMAL;
278 } 275 }
279 276
280 return internal::NiceValueToThreadPriority(nice_value); 277 return internal::NiceValueToThreadPriority(nice_value);
281 #endif // !defined(OS_NACL) 278 #endif // !defined(OS_NACL)
282 } 279 }
283 280
284 #endif // !defined(OS_MACOSX) 281 #endif // !defined(OS_MACOSX)
285 282
286 } // namespace base 283 } // namespace base
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698