OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 "mojo/edk/system/dispatcher.h" | 5 #include "mojo/edk/system/dispatcher.h" |
6 | 6 |
7 #include "base/logging.h" | 7 #include "base/logging.h" |
8 #include "mojo/edk/system/configuration.h" | 8 #include "mojo/edk/system/configuration.h" |
9 #include "mojo/edk/system/message_pipe_dispatcher.h" | 9 #include "mojo/edk/system/message_pipe_dispatcher.h" |
10 #include "mojo/edk/system/platform_handle_dispatcher.h" | 10 #include "mojo/edk/system/platform_handle_dispatcher.h" |
(...skipping 202 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
213 } | 213 } |
214 | 214 |
215 HandleSignalsState Dispatcher::GetHandleSignalsState() const { | 215 HandleSignalsState Dispatcher::GetHandleSignalsState() const { |
216 base::AutoLock locker(lock_); | 216 base::AutoLock locker(lock_); |
217 if (is_closed_) | 217 if (is_closed_) |
218 return HandleSignalsState(); | 218 return HandleSignalsState(); |
219 | 219 |
220 return GetHandleSignalsStateImplNoLock(); | 220 return GetHandleSignalsStateImplNoLock(); |
221 } | 221 } |
222 | 222 |
223 MojoResult Dispatcher::AddWaiter(Waiter* waiter, | 223 MojoResult Dispatcher::AddAwakable(Awakable* awakable, |
224 MojoHandleSignals signals, | 224 MojoHandleSignals signals, |
225 uint32_t context, | 225 uint32_t context, |
226 HandleSignalsState* signals_state) { | 226 HandleSignalsState* signals_state) { |
227 base::AutoLock locker(lock_); | 227 base::AutoLock locker(lock_); |
228 if (is_closed_) { | 228 if (is_closed_) { |
229 if (signals_state) | 229 if (signals_state) |
230 *signals_state = HandleSignalsState(); | 230 *signals_state = HandleSignalsState(); |
231 return MOJO_RESULT_INVALID_ARGUMENT; | 231 return MOJO_RESULT_INVALID_ARGUMENT; |
232 } | 232 } |
233 | 233 |
234 return AddWaiterImplNoLock(waiter, signals, context, signals_state); | 234 return AddAwakableImplNoLock(awakable, signals, context, signals_state); |
235 } | 235 } |
236 | 236 |
237 void Dispatcher::RemoveWaiter(Waiter* waiter, | 237 void Dispatcher::RemoveAwakable(Awakable* awakable, |
238 HandleSignalsState* handle_signals_state) { | 238 HandleSignalsState* handle_signals_state) { |
239 base::AutoLock locker(lock_); | 239 base::AutoLock locker(lock_); |
240 if (is_closed_) { | 240 if (is_closed_) { |
241 if (handle_signals_state) | 241 if (handle_signals_state) |
242 *handle_signals_state = HandleSignalsState(); | 242 *handle_signals_state = HandleSignalsState(); |
243 return; | 243 return; |
244 } | 244 } |
245 RemoveWaiterImplNoLock(waiter, handle_signals_state); | 245 |
| 246 RemoveAwakableImplNoLock(awakable, handle_signals_state); |
246 } | 247 } |
247 | 248 |
248 Dispatcher::Dispatcher() : is_closed_(false) { | 249 Dispatcher::Dispatcher() : is_closed_(false) { |
249 } | 250 } |
250 | 251 |
251 Dispatcher::~Dispatcher() { | 252 Dispatcher::~Dispatcher() { |
252 // Make sure that |Close()| was called. | 253 // Make sure that |Close()| was called. |
253 DCHECK(is_closed_); | 254 DCHECK(is_closed_); |
254 } | 255 } |
255 | 256 |
256 void Dispatcher::CancelAllWaitersNoLock() { | 257 void Dispatcher::CancelAllAwakablesNoLock() { |
257 lock_.AssertAcquired(); | 258 lock_.AssertAcquired(); |
258 DCHECK(is_closed_); | 259 DCHECK(is_closed_); |
259 // By default, waiting isn't supported. Only dispatchers that can be waited on | 260 // By default, waiting isn't supported. Only dispatchers that can be waited on |
260 // will do something nontrivial. | 261 // will do something nontrivial. |
261 } | 262 } |
262 | 263 |
263 void Dispatcher::CloseImplNoLock() { | 264 void Dispatcher::CloseImplNoLock() { |
264 lock_.AssertAcquired(); | 265 lock_.AssertAcquired(); |
265 DCHECK(is_closed_); | 266 DCHECK(is_closed_); |
266 // This may not need to do anything. Dispatchers should override this to do | 267 // This may not need to do anything. Dispatchers should override this to do |
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
363 } | 364 } |
364 | 365 |
365 HandleSignalsState Dispatcher::GetHandleSignalsStateImplNoLock() const { | 366 HandleSignalsState Dispatcher::GetHandleSignalsStateImplNoLock() const { |
366 lock_.AssertAcquired(); | 367 lock_.AssertAcquired(); |
367 DCHECK(!is_closed_); | 368 DCHECK(!is_closed_); |
368 // By default, waiting isn't supported. Only dispatchers that can be waited on | 369 // By default, waiting isn't supported. Only dispatchers that can be waited on |
369 // will do something nontrivial. | 370 // will do something nontrivial. |
370 return HandleSignalsState(); | 371 return HandleSignalsState(); |
371 } | 372 } |
372 | 373 |
373 MojoResult Dispatcher::AddWaiterImplNoLock(Waiter* /*waiter*/, | 374 MojoResult Dispatcher::AddAwakableImplNoLock( |
374 MojoHandleSignals /*signals*/, | 375 Awakable* /*awakable*/, |
375 uint32_t /*context*/, | 376 MojoHandleSignals /*signals*/, |
376 HandleSignalsState* signals_state) { | 377 uint32_t /*context*/, |
| 378 HandleSignalsState* signals_state) { |
377 lock_.AssertAcquired(); | 379 lock_.AssertAcquired(); |
378 DCHECK(!is_closed_); | 380 DCHECK(!is_closed_); |
379 // By default, waiting isn't supported. Only dispatchers that can be waited on | 381 // By default, waiting isn't supported. Only dispatchers that can be waited on |
380 // will do something nontrivial. | 382 // will do something nontrivial. |
381 if (signals_state) | 383 if (signals_state) |
382 *signals_state = HandleSignalsState(); | 384 *signals_state = HandleSignalsState(); |
383 return MOJO_RESULT_FAILED_PRECONDITION; | 385 return MOJO_RESULT_FAILED_PRECONDITION; |
384 } | 386 } |
385 | 387 |
386 void Dispatcher::RemoveWaiterImplNoLock(Waiter* /*waiter*/, | 388 void Dispatcher::RemoveAwakableImplNoLock(Awakable* /*awakable*/, |
387 HandleSignalsState* signals_state) { | 389 HandleSignalsState* signals_state) { |
388 lock_.AssertAcquired(); | 390 lock_.AssertAcquired(); |
389 DCHECK(!is_closed_); | 391 DCHECK(!is_closed_); |
390 // By default, waiting isn't supported. Only dispatchers that can be waited on | 392 // By default, waiting isn't supported. Only dispatchers that can be waited on |
391 // will do something nontrivial. | 393 // will do something nontrivial. |
392 if (signals_state) | 394 if (signals_state) |
393 *signals_state = HandleSignalsState(); | 395 *signals_state = HandleSignalsState(); |
394 } | 396 } |
395 | 397 |
396 void Dispatcher::StartSerializeImplNoLock(Channel* /*channel*/, | 398 void Dispatcher::StartSerializeImplNoLock(Channel* /*channel*/, |
397 size_t* max_size, | 399 size_t* max_size, |
(...skipping 22 matching lines...) Expand all Loading... |
420 // Most dispatchers support only "atomic" operations, so they are never busy | 422 // Most dispatchers support only "atomic" operations, so they are never busy |
421 // (in this sense). | 423 // (in this sense). |
422 return false; | 424 return false; |
423 } | 425 } |
424 | 426 |
425 void Dispatcher::CloseNoLock() { | 427 void Dispatcher::CloseNoLock() { |
426 lock_.AssertAcquired(); | 428 lock_.AssertAcquired(); |
427 DCHECK(!is_closed_); | 429 DCHECK(!is_closed_); |
428 | 430 |
429 is_closed_ = true; | 431 is_closed_ = true; |
430 CancelAllWaitersNoLock(); | 432 CancelAllAwakablesNoLock(); |
431 CloseImplNoLock(); | 433 CloseImplNoLock(); |
432 } | 434 } |
433 | 435 |
434 scoped_refptr<Dispatcher> | 436 scoped_refptr<Dispatcher> |
435 Dispatcher::CreateEquivalentDispatcherAndCloseNoLock() { | 437 Dispatcher::CreateEquivalentDispatcherAndCloseNoLock() { |
436 lock_.AssertAcquired(); | 438 lock_.AssertAcquired(); |
437 DCHECK(!is_closed_); | 439 DCHECK(!is_closed_); |
438 | 440 |
439 is_closed_ = true; | 441 is_closed_ = true; |
440 CancelAllWaitersNoLock(); | 442 CancelAllAwakablesNoLock(); |
441 return CreateEquivalentDispatcherAndCloseImplNoLock(); | 443 return CreateEquivalentDispatcherAndCloseImplNoLock(); |
442 } | 444 } |
443 | 445 |
444 void Dispatcher::StartSerialize(Channel* channel, | 446 void Dispatcher::StartSerialize(Channel* channel, |
445 size_t* max_size, | 447 size_t* max_size, |
446 size_t* max_platform_handles) { | 448 size_t* max_platform_handles) { |
447 DCHECK(channel); | 449 DCHECK(channel); |
448 DCHECK(max_size); | 450 DCHECK(max_size); |
449 DCHECK(max_platform_handles); | 451 DCHECK(max_platform_handles); |
450 DCHECK(HasOneRef()); // Only one ref => no need to take the lock. | 452 DCHECK(HasOneRef()); // Only one ref => no need to take the lock. |
(...skipping 30 matching lines...) Expand all Loading... |
481 // DispatcherTransport --------------------------------------------------------- | 483 // DispatcherTransport --------------------------------------------------------- |
482 | 484 |
483 void DispatcherTransport::End() { | 485 void DispatcherTransport::End() { |
484 DCHECK(dispatcher_); | 486 DCHECK(dispatcher_); |
485 dispatcher_->lock_.Release(); | 487 dispatcher_->lock_.Release(); |
486 dispatcher_ = nullptr; | 488 dispatcher_ = nullptr; |
487 } | 489 } |
488 | 490 |
489 } // namespace system | 491 } // namespace system |
490 } // namespace mojo | 492 } // namespace mojo |
OLD | NEW |