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/system/dispatcher.h" | 5 #include "mojo/system/dispatcher.h" |
6 | 6 |
7 #include "base/logging.h" | 7 #include "base/logging.h" |
8 #include "mojo/system/constants.h" | 8 #include "mojo/system/constants.h" |
9 #include "mojo/system/message_pipe_dispatcher.h" | 9 #include "mojo/system/message_pipe_dispatcher.h" |
10 | 10 |
(...skipping 335 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
346 | 346 |
347 void Dispatcher::RemoveWaiterImplNoLock(Waiter* /*waiter*/) { | 347 void Dispatcher::RemoveWaiterImplNoLock(Waiter* /*waiter*/) { |
348 lock_.AssertAcquired(); | 348 lock_.AssertAcquired(); |
349 DCHECK(!is_closed_); | 349 DCHECK(!is_closed_); |
350 // By default, waiting isn't supported. Only dispatchers that can be waited on | 350 // By default, waiting isn't supported. Only dispatchers that can be waited on |
351 // will do something nontrivial. | 351 // will do something nontrivial. |
352 } | 352 } |
353 | 353 |
354 size_t Dispatcher::GetMaximumSerializedSizeImplNoLock( | 354 size_t Dispatcher::GetMaximumSerializedSizeImplNoLock( |
355 const Channel* /*channel*/) const { | 355 const Channel* /*channel*/) const { |
356 lock_.AssertAcquired(); | 356 DCHECK(HasOneRef()); // Only one ref => no need to take the lock. |
357 DCHECK(!is_closed_); | 357 DCHECK(!is_closed_); |
358 // By default, serializing isn't supported. | 358 // By default, serializing isn't supported. |
359 return 0; | 359 return 0; |
360 } | 360 } |
361 | 361 |
362 bool Dispatcher::SerializeAndCloseImplNoLock(Channel* /*channel*/, | 362 bool Dispatcher::SerializeAndCloseImplNoLock(Channel* /*channel*/, |
363 void* /*destination*/, | 363 void* /*destination*/, |
364 size_t* /*actual_size*/) { | 364 size_t* /*actual_size*/) { |
365 lock_.AssertAcquired(); | 365 DCHECK(HasOneRef()); // Only one ref => no need to take the lock. |
366 DCHECK(is_closed_); | 366 DCHECK(is_closed_); |
367 // By default, serializing isn't supported, so just close. | 367 // By default, serializing isn't supported, so just close. |
368 CloseImplNoLock(); | 368 CloseImplNoLock(); |
369 return 0; | 369 return 0; |
370 } | 370 } |
371 | 371 |
372 bool Dispatcher::IsBusyNoLock() const { | 372 bool Dispatcher::IsBusyNoLock() const { |
373 lock_.AssertAcquired(); | 373 lock_.AssertAcquired(); |
374 DCHECK(!is_closed_); | 374 DCHECK(!is_closed_); |
375 // Most dispatchers support only "atomic" operations, so they are never busy | 375 // Most dispatchers support only "atomic" operations, so they are never busy |
(...skipping 15 matching lines...) Expand all Loading... |
391 lock_.AssertAcquired(); | 391 lock_.AssertAcquired(); |
392 DCHECK(!is_closed_); | 392 DCHECK(!is_closed_); |
393 | 393 |
394 is_closed_ = true; | 394 is_closed_ = true; |
395 CancelAllWaitersNoLock(); | 395 CancelAllWaitersNoLock(); |
396 return CreateEquivalentDispatcherAndCloseImplNoLock(); | 396 return CreateEquivalentDispatcherAndCloseImplNoLock(); |
397 } | 397 } |
398 | 398 |
399 size_t Dispatcher::GetMaximumSerializedSize(const Channel* channel) const { | 399 size_t Dispatcher::GetMaximumSerializedSize(const Channel* channel) const { |
400 DCHECK(channel); | 400 DCHECK(channel); |
401 DCHECK(HasOneRef()); | 401 DCHECK(HasOneRef()); // Only one ref => no need to take the lock. |
402 | |
403 base::AutoLock locker(lock_); | |
404 DCHECK(!is_closed_); | 402 DCHECK(!is_closed_); |
405 return GetMaximumSerializedSizeImplNoLock(channel); | 403 return GetMaximumSerializedSizeImplNoLock(channel); |
406 } | 404 } |
407 | 405 |
408 bool Dispatcher::SerializeAndClose(Channel* channel, | 406 bool Dispatcher::SerializeAndClose(Channel* channel, |
409 void* destination, | 407 void* destination, |
410 size_t* actual_size) { | 408 size_t* actual_size) { |
411 DCHECK(destination); | 409 DCHECK(destination); |
412 DCHECK(channel); | 410 DCHECK(channel); |
413 DCHECK(actual_size); | 411 DCHECK(actual_size); |
414 DCHECK(HasOneRef()); | 412 DCHECK(HasOneRef()); // Only one ref => no need to take the lock. |
415 | |
416 base::AutoLock locker(lock_); | |
417 DCHECK(!is_closed_); | 413 DCHECK(!is_closed_); |
418 | 414 |
419 // We have to call |GetMaximumSerializedSizeImplNoLock()| first, because we | 415 // We have to call |GetMaximumSerializedSizeImplNoLock()| first, because we |
420 // leave it to |SerializeAndCloseImplNoLock()| to close the thing. | 416 // leave it to |SerializeAndCloseImplNoLock()| to close the thing. |
421 #if DCHECK_IS_ON | 417 #if DCHECK_IS_ON |
422 size_t max_size = GetMaximumSerializedSizeImplNoLock(channel); | 418 size_t max_size = GetMaximumSerializedSizeImplNoLock(channel); |
423 #else | 419 #else |
424 size_t max_size = static_cast<size_t>(-1); | 420 size_t max_size = static_cast<size_t>(-1); |
425 #endif | 421 #endif |
426 | 422 |
(...skipping 13 matching lines...) Expand all Loading... |
440 // DispatcherTransport --------------------------------------------------------- | 436 // DispatcherTransport --------------------------------------------------------- |
441 | 437 |
442 void DispatcherTransport::End() { | 438 void DispatcherTransport::End() { |
443 DCHECK(dispatcher_); | 439 DCHECK(dispatcher_); |
444 dispatcher_->lock_.Release(); | 440 dispatcher_->lock_.Release(); |
445 dispatcher_ = NULL; | 441 dispatcher_ = NULL; |
446 } | 442 } |
447 | 443 |
448 } // namespace system | 444 } // namespace system |
449 } // namespace mojo | 445 } // namespace mojo |
OLD | NEW |