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

Side by Side Diff: webrtc/system_wrappers/source/thread_posix.cc

Issue 1335923002: Add RTC_ prefix to (D)CHECKs and related macros. (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: Rebase. Created 5 years, 3 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 | « webrtc/system_wrappers/source/file_impl.cc ('k') | webrtc/system_wrappers/source/thread_win.cc » ('j') | 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) 2012 The WebRTC project authors. All Rights Reserved. 2 * Copyright (c) 2012 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 21 matching lines...) Expand all
32 struct ThreadAttributes { 32 struct ThreadAttributes {
33 ThreadAttributes() { pthread_attr_init(&attr); } 33 ThreadAttributes() { pthread_attr_init(&attr); }
34 ~ThreadAttributes() { pthread_attr_destroy(&attr); } 34 ~ThreadAttributes() { pthread_attr_destroy(&attr); }
35 pthread_attr_t* operator&() { return &attr; } 35 pthread_attr_t* operator&() { return &attr; }
36 pthread_attr_t attr; 36 pthread_attr_t attr;
37 }; 37 };
38 } // namespace 38 } // namespace
39 39
40 int ConvertToSystemPriority(ThreadPriority priority, int min_prio, 40 int ConvertToSystemPriority(ThreadPriority priority, int min_prio,
41 int max_prio) { 41 int max_prio) {
42 DCHECK(max_prio - min_prio > 2); 42 RTC_DCHECK(max_prio - min_prio > 2);
43 const int top_prio = max_prio - 1; 43 const int top_prio = max_prio - 1;
44 const int low_prio = min_prio + 1; 44 const int low_prio = min_prio + 1;
45 45
46 switch (priority) { 46 switch (priority) {
47 case kLowPriority: 47 case kLowPriority:
48 return low_prio; 48 return low_prio;
49 case kNormalPriority: 49 case kNormalPriority:
50 // The -1 ensures that the kHighPriority is always greater or equal to 50 // The -1 ensures that the kHighPriority is always greater or equal to
51 // kNormalPriority. 51 // kNormalPriority.
52 return (low_prio + top_prio - 1) / 2; 52 return (low_prio + top_prio - 1) / 2;
53 case kHighPriority: 53 case kHighPriority:
54 return std::max(top_prio - 2, low_prio); 54 return std::max(top_prio - 2, low_prio);
55 case kHighestPriority: 55 case kHighestPriority:
56 return std::max(top_prio - 1, low_prio); 56 return std::max(top_prio - 1, low_prio);
57 case kRealtimePriority: 57 case kRealtimePriority:
58 return top_prio; 58 return top_prio;
59 } 59 }
60 DCHECK(false); 60 RTC_DCHECK(false);
61 return low_prio; 61 return low_prio;
62 } 62 }
63 63
64 // static 64 // static
65 void* ThreadPosix::StartThread(void* param) { 65 void* ThreadPosix::StartThread(void* param) {
66 static_cast<ThreadPosix*>(param)->Run(); 66 static_cast<ThreadPosix*>(param)->Run();
67 return 0; 67 return 0;
68 } 68 }
69 69
70 ThreadPosix::ThreadPosix(ThreadRunFunction func, void* obj, 70 ThreadPosix::ThreadPosix(ThreadRunFunction func, void* obj,
71 const char* thread_name) 71 const char* thread_name)
72 : run_function_(func), 72 : run_function_(func),
73 obj_(obj), 73 obj_(obj),
74 stop_event_(false, false), 74 stop_event_(false, false),
75 name_(thread_name ? thread_name : "webrtc"), 75 name_(thread_name ? thread_name : "webrtc"),
76 thread_(0) { 76 thread_(0) {
77 DCHECK(name_.length() < 64); 77 RTC_DCHECK(name_.length() < 64);
78 } 78 }
79 79
80 uint32_t ThreadWrapper::GetThreadId() { 80 uint32_t ThreadWrapper::GetThreadId() {
81 return rtc::CurrentThreadId(); 81 return rtc::CurrentThreadId();
82 } 82 }
83 83
84 ThreadPosix::~ThreadPosix() { 84 ThreadPosix::~ThreadPosix() {
85 DCHECK(thread_checker_.CalledOnValidThread()); 85 RTC_DCHECK(thread_checker_.CalledOnValidThread());
86 } 86 }
87 87
88 // TODO(pbos): Make Start void, calling code really doesn't support failures 88 // TODO(pbos): Make Start void, calling code really doesn't support failures
89 // here. 89 // here.
90 bool ThreadPosix::Start() { 90 bool ThreadPosix::Start() {
91 DCHECK(thread_checker_.CalledOnValidThread()); 91 RTC_DCHECK(thread_checker_.CalledOnValidThread());
92 DCHECK(!thread_) << "Thread already started?"; 92 RTC_DCHECK(!thread_) << "Thread already started?";
93 93
94 ThreadAttributes attr; 94 ThreadAttributes attr;
95 // Set the stack stack size to 1M. 95 // Set the stack stack size to 1M.
96 pthread_attr_setstacksize(&attr, 1024 * 1024); 96 pthread_attr_setstacksize(&attr, 1024 * 1024);
97 CHECK_EQ(0, pthread_create(&thread_, &attr, &StartThread, this)); 97 RTC_CHECK_EQ(0, pthread_create(&thread_, &attr, &StartThread, this));
98 return true; 98 return true;
99 } 99 }
100 100
101 bool ThreadPosix::Stop() { 101 bool ThreadPosix::Stop() {
102 DCHECK(thread_checker_.CalledOnValidThread()); 102 RTC_DCHECK(thread_checker_.CalledOnValidThread());
103 if (!thread_) 103 if (!thread_)
104 return true; 104 return true;
105 105
106 stop_event_.Set(); 106 stop_event_.Set();
107 CHECK_EQ(0, pthread_join(thread_, nullptr)); 107 RTC_CHECK_EQ(0, pthread_join(thread_, nullptr));
108 thread_ = 0; 108 thread_ = 0;
109 109
110 return true; 110 return true;
111 } 111 }
112 112
113 bool ThreadPosix::SetPriority(ThreadPriority priority) { 113 bool ThreadPosix::SetPriority(ThreadPriority priority) {
114 DCHECK(thread_checker_.CalledOnValidThread()); 114 RTC_DCHECK(thread_checker_.CalledOnValidThread());
115 if (!thread_) 115 if (!thread_)
116 return false; 116 return false;
117 #if defined(WEBRTC_CHROMIUM_BUILD) && defined(WEBRTC_LINUX) 117 #if defined(WEBRTC_CHROMIUM_BUILD) && defined(WEBRTC_LINUX)
118 // TODO(tommi): Switch to the same mechanism as Chromium uses for 118 // TODO(tommi): Switch to the same mechanism as Chromium uses for
119 // changing thread priorities. 119 // changing thread priorities.
120 return true; 120 return true;
121 #else 121 #else
122 #ifdef WEBRTC_THREAD_RR 122 #ifdef WEBRTC_THREAD_RR
123 const int policy = SCHED_RR; 123 const int policy = SCHED_RR;
124 #else 124 #else
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
157 // It's a requirement that for successful thread creation that the run 157 // It's a requirement that for successful thread creation that the run
158 // function be called at least once (see RunFunctionIsCalled unit test), 158 // function be called at least once (see RunFunctionIsCalled unit test),
159 // so to fullfill that requirement, we use a |do| loop and not |while|. 159 // so to fullfill that requirement, we use a |do| loop and not |while|.
160 do { 160 do {
161 if (!run_function_(obj_)) 161 if (!run_function_(obj_))
162 break; 162 break;
163 } while (!stop_event_.Wait(0)); 163 } while (!stop_event_.Wait(0));
164 } 164 }
165 165
166 } // namespace webrtc 166 } // namespace webrtc
OLDNEW
« no previous file with comments | « webrtc/system_wrappers/source/file_impl.cc ('k') | webrtc/system_wrappers/source/thread_win.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698