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 "media/audio/cross_process_notification.h" | 5 #include "media/audio/cross_process_notification.h" |
6 | 6 |
7 #include "base/logging.h" | 7 #include "base/logging.h" |
8 #include "base/memory/scoped_ptr.h" | 8 #include "base/memory/scoped_ptr.h" |
9 #include "base/threading/platform_thread.h" | 9 #include "base/threading/platform_thread.h" |
10 #include "base/win/scoped_handle.h" | 10 #include "base/win/scoped_handle.h" |
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
114 DWORD event_count = MAXIMUM_WAIT_OBJECTS; | 114 DWORD event_count = MAXIMUM_WAIT_OBJECTS; |
115 int thread_signaled_event = -1; | 115 int thread_signaled_event = -1; |
116 scoped_ptr<ExtraWaitThread> extra_wait_thread; | 116 scoped_ptr<ExtraWaitThread> extra_wait_thread; |
117 if (count_ > (MAXIMUM_WAIT_OBJECTS - 1)) { | 117 if (count_ > (MAXIMUM_WAIT_OBJECTS - 1)) { |
118 std::copy(&events_[0], &events_[MAXIMUM_WAIT_OBJECTS - 2], &events[1]); | 118 std::copy(&events_[0], &events_[MAXIMUM_WAIT_OBJECTS - 2], &events[1]); |
119 | 119 |
120 extra_wait_thread.reset(new ExtraWaitThread(stop_, | 120 extra_wait_thread.reset(new ExtraWaitThread(stop_, |
121 &events_[MAXIMUM_WAIT_OBJECTS - 2], | 121 &events_[MAXIMUM_WAIT_OBJECTS - 2], |
122 count_ - (MAXIMUM_WAIT_OBJECTS - 2), | 122 count_ - (MAXIMUM_WAIT_OBJECTS - 2), |
123 &thread_signaled_event)); | 123 &thread_signaled_event)); |
124 base::PlatformThread::Create(0, extra_wait_thread.get(), &next_thread); | 124 base::PlatformThreadHandle handle; |
| 125 base::PlatformThread::Create(0, extra_wait_thread.get(), &handle); |
| 126 next_thread = handle.platform_handle(); |
125 | 127 |
126 event_count = MAXIMUM_WAIT_OBJECTS; | 128 event_count = MAXIMUM_WAIT_OBJECTS; |
127 events[MAXIMUM_WAIT_OBJECTS - 1] = next_thread; | 129 events[MAXIMUM_WAIT_OBJECTS - 1] = next_thread; |
128 } else { | 130 } else { |
129 std::copy(&events_[0], &events_[count_], &events[1]); | 131 std::copy(&events_[0], &events_[count_], &events[1]); |
130 event_count = count_ + 1; | 132 event_count = count_ + 1; |
131 } | 133 } |
132 | 134 |
133 DWORD wait = ::WaitForMultipleObjects(event_count, &events[0], FALSE, | 135 DWORD wait = ::WaitForMultipleObjects(event_count, &events[0], FALSE, |
134 INFINITE); | 136 INFINITE); |
135 if (wait >= WAIT_OBJECT_0 && wait < (WAIT_OBJECT_0 + event_count)) { | 137 if (wait >= WAIT_OBJECT_0 && wait < (WAIT_OBJECT_0 + event_count)) { |
136 wait -= WAIT_OBJECT_0; | 138 wait -= WAIT_OBJECT_0; |
137 if (wait == 0) { | 139 if (wait == 0) { |
138 // The stop event was signaled. Check if it was signaled by a | 140 // The stop event was signaled. Check if it was signaled by a |
139 // sub thread. In case our sub thread had to spin another thread (and | 141 // sub thread. In case our sub thread had to spin another thread (and |
140 // so on), we must wait for ours to exit before we can check the | 142 // so on), we must wait for ours to exit before we can check the |
141 // propagated event offset. | 143 // propagated event offset. |
142 if (next_thread) { | 144 if (next_thread) { |
143 base::PlatformThread::Join(next_thread); | 145 base::PlatformThread::Join(base::PlatformThreadHandle(next_thread)); |
144 next_thread = NULL; | 146 next_thread = NULL; |
145 } | 147 } |
146 if (thread_signaled_event != -1) | 148 if (thread_signaled_event != -1) |
147 *signaled_event_ = thread_signaled_event + (MAXIMUM_WAIT_OBJECTS - 2); | 149 *signaled_event_ = thread_signaled_event + (MAXIMUM_WAIT_OBJECTS - 2); |
148 } else if (events[wait] == next_thread) { | 150 } else if (events[wait] == next_thread) { |
149 NOTREACHED(); | 151 NOTREACHED(); |
150 } else { | 152 } else { |
151 *signaled_event_ = static_cast<int>(wait); | 153 *signaled_event_ = static_cast<int>(wait); |
152 SetEvent(stop_); | 154 SetEvent(stop_); |
153 } | 155 } |
154 } else { | 156 } else { |
155 NOTREACHED(); | 157 NOTREACHED(); |
156 } | 158 } |
157 | 159 |
158 if (next_thread) | 160 if (next_thread) |
159 base::PlatformThread::Join(next_thread); | 161 base::PlatformThread::Join(base::PlatformThreadHandle(next_thread)); |
160 } | 162 } |
161 | 163 |
162 private: | 164 private: |
163 HANDLE stop_; | 165 HANDLE stop_; |
164 HANDLE* events_; | 166 HANDLE* events_; |
165 size_t count_; | 167 size_t count_; |
166 int* signaled_event_; | 168 int* signaled_event_; |
167 DISALLOW_COPY_AND_ASSIGN(ExtraWaitThread); | 169 DISALLOW_COPY_AND_ASSIGN(ExtraWaitThread); |
168 }; | 170 }; |
169 } // end namespace | 171 } // end namespace |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
225 // being signaled). | 227 // being signaled). |
226 | 228 |
227 int thread_signaled_event = -1; | 229 int thread_signaled_event = -1; |
228 ExtraWaitThread wait_thread(stop, &handles[MAXIMUM_WAIT_OBJECTS - 1], | 230 ExtraWaitThread wait_thread(stop, &handles[MAXIMUM_WAIT_OBJECTS - 1], |
229 notifications.size() - (MAXIMUM_WAIT_OBJECTS - 1), | 231 notifications.size() - (MAXIMUM_WAIT_OBJECTS - 1), |
230 &thread_signaled_event); | 232 &thread_signaled_event); |
231 base::PlatformThreadHandle thread; | 233 base::PlatformThreadHandle thread; |
232 base::PlatformThread::Create(0, &wait_thread, &thread); | 234 base::PlatformThread::Create(0, &wait_thread, &thread); |
233 HANDLE events[MAXIMUM_WAIT_OBJECTS]; | 235 HANDLE events[MAXIMUM_WAIT_OBJECTS]; |
234 std::copy(&handles[0], &handles[MAXIMUM_WAIT_OBJECTS - 1], &events[0]); | 236 std::copy(&handles[0], &handles[MAXIMUM_WAIT_OBJECTS - 1], &events[0]); |
235 events[MAXIMUM_WAIT_OBJECTS - 1] = thread; | 237 events[MAXIMUM_WAIT_OBJECTS - 1] = thread.platform_handle(); |
236 wait = ::WaitForMultipleObjects(MAXIMUM_WAIT_OBJECTS, &events[0], FALSE, | 238 wait = ::WaitForMultipleObjects(MAXIMUM_WAIT_OBJECTS, &events[0], FALSE, |
237 INFINITE); | 239 INFINITE); |
238 wait_failed = wait < WAIT_OBJECT_0 || | 240 wait_failed = wait < WAIT_OBJECT_0 || |
239 wait >= (WAIT_OBJECT_0 + MAXIMUM_WAIT_OBJECTS); | 241 wait >= (WAIT_OBJECT_0 + MAXIMUM_WAIT_OBJECTS); |
240 if (wait == WAIT_OBJECT_0 + (MAXIMUM_WAIT_OBJECTS - 1)) { | 242 if (wait == WAIT_OBJECT_0 + (MAXIMUM_WAIT_OBJECTS - 1)) { |
241 if (thread_signaled_event < 0) { | 243 if (thread_signaled_event < 0) { |
242 wait_failed = true; | 244 wait_failed = true; |
243 NOTREACHED(); | 245 NOTREACHED(); |
244 } else { | 246 } else { |
245 wait = WAIT_OBJECT_0 + (MAXIMUM_WAIT_OBJECTS - 2) + | 247 wait = WAIT_OBJECT_0 + (MAXIMUM_WAIT_OBJECTS - 2) + |
(...skipping 13 matching lines...) Expand all Loading... |
259 CHECK(ok); | 261 CHECK(ok); |
260 ret = (wait + wait_offset) % notifications.size(); | 262 ret = (wait + wait_offset) % notifications.size(); |
261 DCHECK_EQ(handles[wait], notifications[ret]->other_.Get()); | 263 DCHECK_EQ(handles[wait], notifications[ret]->other_.Get()); |
262 } else { | 264 } else { |
263 NOTREACHED(); | 265 NOTREACHED(); |
264 } | 266 } |
265 | 267 |
266 CHECK_NE(ret, -1); | 268 CHECK_NE(ret, -1); |
267 return ret; | 269 return ret; |
268 } | 270 } |
OLD | NEW |