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

Side by Side Diff: mojo/edk/system/dispatcher.cc

Issue 2061913002: Don't call the other wait set impl dispatcher methods under mutex either. (Closed) Base URL: https://github.com/domokit/mojo.git@master
Patch Set: Created 4 years, 6 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 | « mojo/edk/system/dispatcher.h ('k') | mojo/edk/system/wait_set_dispatcher.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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/data_pipe_consumer_dispatcher.h" 9 #include "mojo/edk/system/data_pipe_consumer_dispatcher.h"
10 #include "mojo/edk/system/data_pipe_producer_dispatcher.h" 10 #include "mojo/edk/system/data_pipe_producer_dispatcher.h"
(...skipping 258 matching lines...) Expand 10 before | Expand all | Expand 10 after
269 uint64_t num_bytes, 269 uint64_t num_bytes,
270 MojoMapBufferFlags flags, 270 MojoMapBufferFlags flags,
271 std::unique_ptr<PlatformSharedBufferMapping>* mapping) { 271 std::unique_ptr<PlatformSharedBufferMapping>* mapping) {
272 MutexLocker locker(&mutex_); 272 MutexLocker locker(&mutex_);
273 if (is_closed_) 273 if (is_closed_)
274 return MOJO_RESULT_INVALID_ARGUMENT; 274 return MOJO_RESULT_INVALID_ARGUMENT;
275 275
276 return MapBufferImplNoLock(offset, num_bytes, flags, mapping); 276 return MapBufferImplNoLock(offset, num_bytes, flags, mapping);
277 } 277 }
278 278
279 // Note: The following three wait set methods don't lock |mutex_|, and leave
280 // everything for |WaitSet...Impl()| to do. (We could just make these methods
281 // virtual, but we prefer to have a separate "impl" methods for consistency.)
279 MojoResult Dispatcher::WaitSetAdd( 282 MojoResult Dispatcher::WaitSetAdd(
280 UserPointer<const MojoWaitSetAddOptions> options, 283 UserPointer<const MojoWaitSetAddOptions> options,
281 Handle&& handle, 284 Handle&& handle,
282 MojoHandleSignals signals, 285 MojoHandleSignals signals,
283 uint64_t cookie) { 286 uint64_t cookie) {
284 MutexLocker locker(&mutex_); 287 return WaitSetAddImpl(options, std::move(handle), signals, cookie);
285 if (is_closed_)
286 return MOJO_RESULT_INVALID_ARGUMENT;
287
288 return WaitSetAddImplNoLock(options, std::move(handle), signals, cookie);
289 } 288 }
290 289
291 MojoResult Dispatcher::WaitSetRemove(uint64_t cookie) { 290 MojoResult Dispatcher::WaitSetRemove(uint64_t cookie) {
292 MutexLocker locker(&mutex_); 291 return WaitSetRemoveImpl(cookie);
293 if (is_closed_)
294 return MOJO_RESULT_INVALID_ARGUMENT;
295
296 return WaitSetRemoveImplNoLock(cookie);
297 } 292 }
298 293
299 MojoResult Dispatcher::WaitSetWait(MojoDeadline deadline, 294 MojoResult Dispatcher::WaitSetWait(MojoDeadline deadline,
300 UserPointer<uint32_t> num_results, 295 UserPointer<uint32_t> num_results,
301 UserPointer<MojoWaitSetResult> results, 296 UserPointer<MojoWaitSetResult> results,
302 UserPointer<uint32_t> max_results) { 297 UserPointer<uint32_t> max_results) {
303 // Note: This doesn't lock |mutex_|, and leaves everything for
304 // |WaitSetWaitImpl()| to do. (We could just make this method virtual, but we
305 // prefer to have a separate "impl" method for consistency.)
306 return WaitSetWaitImpl(deadline, num_results, results, max_results); 298 return WaitSetWaitImpl(deadline, num_results, results, max_results);
307 } 299 }
308 300
309 HandleSignalsState Dispatcher::GetHandleSignalsState() const { 301 HandleSignalsState Dispatcher::GetHandleSignalsState() const {
310 MutexLocker locker(&mutex_); 302 MutexLocker locker(&mutex_);
311 if (is_closed_) 303 if (is_closed_)
312 return HandleSignalsState(); 304 return HandleSignalsState();
313 305
314 return GetHandleSignalsStateImplNoLock(); 306 return GetHandleSignalsStateImplNoLock();
315 } 307 }
(...skipping 187 matching lines...) Expand 10 before | Expand all | Expand 10 after
503 uint64_t /*offset*/, 495 uint64_t /*offset*/,
504 uint64_t /*num_bytes*/, 496 uint64_t /*num_bytes*/,
505 MojoMapBufferFlags /*flags*/, 497 MojoMapBufferFlags /*flags*/,
506 std::unique_ptr<PlatformSharedBufferMapping>* /*mapping*/) { 498 std::unique_ptr<PlatformSharedBufferMapping>* /*mapping*/) {
507 mutex_.AssertHeld(); 499 mutex_.AssertHeld();
508 DCHECK(!is_closed_); 500 DCHECK(!is_closed_);
509 // By default, not supported. Only needed for buffer dispatchers. 501 // By default, not supported. Only needed for buffer dispatchers.
510 return MOJO_RESULT_INVALID_ARGUMENT; 502 return MOJO_RESULT_INVALID_ARGUMENT;
511 } 503 }
512 504
513 MojoResult Dispatcher::WaitSetAddImplNoLock( 505 // Note that the following three methods are *not* called under |mutex_| and
506 // |is_closed_| hasn't been checked. However, since we'll return
507 // |MOJO_RESULT_INVALID_ARGUMENT| regardless of the value of |is_closed_| (these
508 // methods are only needed for wait set dispatchers), we don't need to lock
509 // |mutex_| and check |is_closed_|.
510 MojoResult Dispatcher::WaitSetAddImpl(
514 UserPointer<const MojoWaitSetAddOptions> /*options*/, 511 UserPointer<const MojoWaitSetAddOptions> /*options*/,
515 Handle&& /*handle*/, 512 Handle&& /*handle*/,
516 MojoHandleSignals /*signals*/, 513 MojoHandleSignals /*signals*/,
517 uint64_t /*cookie*/) { 514 uint64_t /*cookie*/) {
518 mutex_.AssertHeld(); 515 // See note above.
519 DCHECK(!is_closed_);
520 // By default, not supported. Only needed for wait set dispatchers.
521 return MOJO_RESULT_INVALID_ARGUMENT; 516 return MOJO_RESULT_INVALID_ARGUMENT;
522 } 517 }
523 518
524 MojoResult Dispatcher::WaitSetRemoveImplNoLock(uint64_t /*cookie*/) { 519 MojoResult Dispatcher::WaitSetRemoveImpl(uint64_t /*cookie*/) {
525 mutex_.AssertHeld(); 520 // See note above |WaitSetAddImpl()|.
526 DCHECK(!is_closed_);
527 // By default, not supported. Only needed for wait set dispatchers.
528 return MOJO_RESULT_INVALID_ARGUMENT; 521 return MOJO_RESULT_INVALID_ARGUMENT;
529 } 522 }
530 523
531 MojoResult Dispatcher::WaitSetWaitImpl( 524 MojoResult Dispatcher::WaitSetWaitImpl(
532 MojoDeadline /*deadline*/, 525 MojoDeadline /*deadline*/,
533 UserPointer<uint32_t> /*num_results*/, 526 UserPointer<uint32_t> /*num_results*/,
534 UserPointer<MojoWaitSetResult> /*results*/, 527 UserPointer<MojoWaitSetResult> /*results*/,
535 UserPointer<uint32_t> /*max_results*/) { 528 UserPointer<uint32_t> /*max_results*/) {
536 // Note that this is *not* called under |mutex_| and |is_closed_| hasn't been 529 // See note above |WaitSetAddImpl()|.
537 // checked. But since we'll return |MOJO_RESULT_INVALID_ARGUMENT| in either
538 // case (by default, this is not supported: it's only needed for wait set
539 // dispatchers), we don't need to lock |mutex_| and check |is_closed_|.
540 return MOJO_RESULT_INVALID_ARGUMENT; 530 return MOJO_RESULT_INVALID_ARGUMENT;
541 } 531 }
542 532
543 HandleSignalsState Dispatcher::GetHandleSignalsStateImplNoLock() const { 533 HandleSignalsState Dispatcher::GetHandleSignalsStateImplNoLock() const {
544 mutex_.AssertHeld(); 534 mutex_.AssertHeld();
545 DCHECK(!is_closed_); 535 DCHECK(!is_closed_);
546 // By default, waiting isn't supported. Only dispatchers that can be waited on 536 // By default, waiting isn't supported. Only dispatchers that can be waited on
547 // will do something nontrivial. 537 // will do something nontrivial.
548 return HandleSignalsState(); 538 return HandleSignalsState();
549 } 539 }
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after
644 // want to remove or weaken). 634 // want to remove or weaken).
645 MutexLocker locker(&mutex_); 635 MutexLocker locker(&mutex_);
646 #endif 636 #endif
647 637
648 return EndSerializeAndCloseImplNoLock(channel, destination, actual_size, 638 return EndSerializeAndCloseImplNoLock(channel, destination, actual_size,
649 platform_handles); 639 platform_handles);
650 } 640 }
651 641
652 } // namespace system 642 } // namespace system
653 } // namespace mojo 643 } // namespace mojo
OLDNEW
« no previous file with comments | « mojo/edk/system/dispatcher.h ('k') | mojo/edk/system/wait_set_dispatcher.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698