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

Side by Side Diff: webrtc/base/platform_thread.cc

Issue 2716683002: Use sched_yield on all POSIX platforms in PlatformThread. (Closed)
Patch Set: Created 3 years, 10 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
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright (c) 2015 The WebRTC project authors. All Rights Reserved. 2 * Copyright (c) 2015 The WebRTC project authors. All Rights Reserved.
3 * 3 *
4 * Use of this source code is governed by a BSD-style license 4 * Use of this source code is governed by a BSD-style license
5 * that can be found in the LICENSE file in the root of the source 5 * that can be found in the LICENSE file in the root of the source
6 * tree. An additional intellectual property rights grant can be found 6 * tree. An additional intellectual property rights grant can be found
7 * in the file PATENTS. All contributing project authors may 7 * in the file PATENTS. All contributing project authors may
8 * be found in the AUTHORS file in the root of the source tree. 8 * be found in the AUTHORS file in the root of the source tree.
9 */ 9 */
10 10
(...skipping 203 matching lines...) Expand 10 before | Expand all | Expand 10 after
214 // Attach the worker thread checker to this thread. 214 // Attach the worker thread checker to this thread.
215 RTC_DCHECK(spawned_thread_checker_.CalledOnValidThread()); 215 RTC_DCHECK(spawned_thread_checker_.CalledOnValidThread());
216 rtc::SetCurrentThreadName(name_.c_str()); 216 rtc::SetCurrentThreadName(name_.c_str());
217 217
218 if (run_function_) { 218 if (run_function_) {
219 SetPriority(priority_); 219 SetPriority(priority_);
220 run_function_(obj_); 220 run_function_(obj_);
221 return; 221 return;
222 } 222 }
223 // TODO(tommi): Delete the below. 223 // TODO(tommi): Delete the below.
224 #if !defined(WEBRTC_MAC) && !defined(WEBRTC_WIN)
225 const struct timespec ts_null = {0};
226 #endif
227 do { 224 do {
228 // The interface contract of Start/Stop is that for a successful call to 225 // The interface contract of Start/Stop is that for a successful call to
229 // Start, there should be at least one call to the run function. So we 226 // Start, there should be at least one call to the run function. So we
230 // call the function before checking |stop_|. 227 // call the function before checking |stop_|.
231 if (!run_function_deprecated_(obj_)) 228 if (!run_function_deprecated_(obj_))
232 break; 229 break;
233 #if defined(WEBRTC_WIN) 230 #if defined(WEBRTC_WIN)
234 // Alertable sleep to permit RaiseFlag to run and update |stop_|. 231 // Alertable sleep to permit RaiseFlag to run and update |stop_|.
235 SleepEx(0, true); 232 SleepEx(0, true);
236 } while (!stop_); 233 } while (!stop_);
237 #else 234 #else
238 #if defined(WEBRTC_MAC)
239 sched_yield(); 235 sched_yield();
240 #else
241 nanosleep(&ts_null, nullptr);
242 #endif
243 } while (!AtomicOps::AcquireLoad(&stop_flag_)); 236 } while (!AtomicOps::AcquireLoad(&stop_flag_));
244 #endif // defined(WEBRTC_WIN) 237 #endif // defined(WEBRTC_WIN)
245 } 238 }
246 239
247 bool PlatformThread::SetPriority(ThreadPriority priority) { 240 bool PlatformThread::SetPriority(ThreadPriority priority) {
248 #if RTC_DCHECK_IS_ON 241 #if RTC_DCHECK_IS_ON
249 if (run_function_) { 242 if (run_function_) {
250 // The non-deprecated way of how this function gets called, is that it must 243 // The non-deprecated way of how this function gets called, is that it must
251 // be called on the worker thread itself. 244 // be called on the worker thread itself.
252 RTC_DCHECK(spawned_thread_checker_.CalledOnValidThread()); 245 RTC_DCHECK(spawned_thread_checker_.CalledOnValidThread());
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
312 #if defined(WEBRTC_WIN) 305 #if defined(WEBRTC_WIN)
313 bool PlatformThread::QueueAPC(PAPCFUNC function, ULONG_PTR data) { 306 bool PlatformThread::QueueAPC(PAPCFUNC function, ULONG_PTR data) {
314 RTC_DCHECK(thread_checker_.CalledOnValidThread()); 307 RTC_DCHECK(thread_checker_.CalledOnValidThread());
315 RTC_DCHECK(IsRunning()); 308 RTC_DCHECK(IsRunning());
316 309
317 return QueueUserAPC(function, thread_, data) != FALSE; 310 return QueueUserAPC(function, thread_, data) != FALSE;
318 } 311 }
319 #endif 312 #endif
320 313
321 } // namespace rtc 314 } // namespace rtc
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698