Chromium Code Reviews| 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/limits.h" | 8 #include "mojo/system/limits.h" |
| 9 | 9 |
| 10 namespace mojo { | 10 namespace mojo { |
| (...skipping 17 matching lines...) Expand all Loading... | |
| 28 | 28 |
| 29 base::AutoLock locker(lock_); | 29 base::AutoLock locker(lock_); |
| 30 if (is_closed_) | 30 if (is_closed_) |
| 31 return MOJO_RESULT_INVALID_ARGUMENT; | 31 return MOJO_RESULT_INVALID_ARGUMENT; |
| 32 | 32 |
| 33 return WriteMessageImplNoLock(bytes, num_bytes, dispatchers, flags); | 33 return WriteMessageImplNoLock(bytes, num_bytes, dispatchers, flags); |
| 34 } | 34 } |
| 35 | 35 |
| 36 MojoResult Dispatcher::ReadMessage( | 36 MojoResult Dispatcher::ReadMessage( |
| 37 void* bytes, uint32_t* num_bytes, | 37 void* bytes, uint32_t* num_bytes, |
| 38 uint32_t max_num_dispatchers, | |
| 39 std::vector<scoped_refptr<Dispatcher> >* dispatchers, | 38 std::vector<scoped_refptr<Dispatcher> >* dispatchers, |
| 39 uint32_t* num_dispatchers, | |
|
DaveMoore
2013/11/13 02:54:02
Nit: Why do you need an output var for num_dispatc
| |
| 40 MojoReadMessageFlags flags) { | 40 MojoReadMessageFlags flags) { |
| 41 DCHECK(max_num_dispatchers == 0 || (dispatchers && dispatchers->empty())); | 41 DCHECK(!num_dispatchers || *num_dispatchers == 0 || |
| 42 (dispatchers && dispatchers->empty())); | |
| 42 | 43 |
| 43 base::AutoLock locker(lock_); | 44 base::AutoLock locker(lock_); |
| 44 if (is_closed_) | 45 if (is_closed_) |
| 45 return MOJO_RESULT_INVALID_ARGUMENT; | 46 return MOJO_RESULT_INVALID_ARGUMENT; |
| 46 | 47 |
| 47 return ReadMessageImplNoLock(bytes, num_bytes, | 48 return ReadMessageImplNoLock(bytes, num_bytes, |
| 48 max_num_dispatchers, dispatchers, | 49 dispatchers, num_dispatchers, |
| 49 flags); | 50 flags); |
| 50 } | 51 } |
| 51 | 52 |
| 52 MojoResult Dispatcher::AddWaiter(Waiter* waiter, | 53 MojoResult Dispatcher::AddWaiter(Waiter* waiter, |
| 53 MojoWaitFlags flags, | 54 MojoWaitFlags flags, |
| 54 MojoResult wake_result) { | 55 MojoResult wake_result) { |
| 55 DCHECK_GE(wake_result, 0); | 56 DCHECK_GE(wake_result, 0); |
| 56 | 57 |
| 57 base::AutoLock locker(lock_); | 58 base::AutoLock locker(lock_); |
| 58 if (is_closed_) | 59 if (is_closed_) |
| (...skipping 11 matching lines...) Expand all Loading... | |
| 70 | 71 |
| 71 Dispatcher::Dispatcher() | 72 Dispatcher::Dispatcher() |
| 72 : is_closed_(false) { | 73 : is_closed_(false) { |
| 73 } | 74 } |
| 74 | 75 |
| 75 Dispatcher::~Dispatcher() { | 76 Dispatcher::~Dispatcher() { |
| 76 // Make sure that |Close()| was called. | 77 // Make sure that |Close()| was called. |
| 77 DCHECK(is_closed_); | 78 DCHECK(is_closed_); |
| 78 } | 79 } |
| 79 | 80 |
| 81 scoped_refptr<Dispatcher> | |
| 82 Dispatcher::CreateEquivalentDispatcherAndCloseNoLock() { | |
| 83 lock_.AssertAcquired(); | |
| 84 DCHECK(!is_closed_); | |
| 85 | |
| 86 is_closed_ = true; | |
| 87 CancelAllWaitersNoLock(); | |
| 88 return CreateEquivalentDispatcherAndCloseImplNoLock(); | |
| 89 } | |
| 90 | |
| 80 void Dispatcher::CancelAllWaitersNoLock() { | 91 void Dispatcher::CancelAllWaitersNoLock() { |
| 81 lock_.AssertAcquired(); | 92 lock_.AssertAcquired(); |
| 82 DCHECK(is_closed_); | 93 DCHECK(is_closed_); |
| 83 // By default, waiting isn't supported. Only dispatchers that can be waited on | 94 // By default, waiting isn't supported. Only dispatchers that can be waited on |
| 84 // will do something nontrivial. | 95 // will do something nontrivial. |
| 85 } | 96 } |
| 86 | 97 |
| 87 MojoResult Dispatcher::CloseImplNoLock() { | 98 MojoResult Dispatcher::CloseImplNoLock() { |
| 88 lock_.AssertAcquired(); | 99 lock_.AssertAcquired(); |
| 89 DCHECK(is_closed_); | 100 DCHECK(is_closed_); |
| 90 // This may not need to do anything. Dispatchers should override this to do | 101 // This may not need to do anything. Dispatchers should override this to do |
| 91 // any actual close-time cleanup necessary. | 102 // any actual close-time cleanup necessary. |
| 92 return MOJO_RESULT_OK; | 103 return MOJO_RESULT_OK; |
| 93 } | 104 } |
| 94 | 105 |
| 95 MojoResult Dispatcher::WriteMessageImplNoLock( | 106 MojoResult Dispatcher::WriteMessageImplNoLock( |
| 96 const void* bytes, uint32_t num_bytes, | 107 const void* bytes, uint32_t num_bytes, |
| 97 const std::vector<Dispatcher*>* dispatchers, | 108 const std::vector<Dispatcher*>* dispatchers, |
| 98 MojoWriteMessageFlags flags) { | 109 MojoWriteMessageFlags flags) { |
| 99 lock_.AssertAcquired(); | 110 lock_.AssertAcquired(); |
| 100 DCHECK(!is_closed_); | 111 DCHECK(!is_closed_); |
| 101 // By default, this isn't supported. Only dispatchers for message pipes (with | 112 // By default, this isn't supported. Only dispatchers for message pipes (with |
| 102 // whatever implementation, possibly a proxy) will do something nontrivial. | 113 // whatever implementation, possibly a proxy) will do something nontrivial. |
| 103 return MOJO_RESULT_INVALID_ARGUMENT; | 114 return MOJO_RESULT_INVALID_ARGUMENT; |
| 104 } | 115 } |
| 105 | 116 |
| 106 MojoResult Dispatcher::ReadMessageImplNoLock( | 117 MojoResult Dispatcher::ReadMessageImplNoLock( |
| 107 void* bytes, uint32_t* num_bytes, | 118 void* /*bytes*/, uint32_t* /*num_bytes*/, |
| 108 uint32_t max_num_dispatchers, | 119 std::vector<scoped_refptr<Dispatcher> >* /*dispatchers*/, |
| 109 std::vector<scoped_refptr<Dispatcher> >* dispatchers, | 120 uint32_t* /*num_dispatchers*/, |
| 110 MojoReadMessageFlags flags) { | 121 MojoReadMessageFlags /*flags*/) { |
| 111 lock_.AssertAcquired(); | 122 lock_.AssertAcquired(); |
| 112 DCHECK(!is_closed_); | 123 DCHECK(!is_closed_); |
| 113 // By default, this isn't supported. Only dispatchers for message pipes (with | 124 // By default, this isn't supported. Only dispatchers for message pipes (with |
| 114 // whatever implementation, possibly a proxy) will do something nontrivial. | 125 // whatever implementation, possibly a proxy) will do something nontrivial. |
| 115 return MOJO_RESULT_INVALID_ARGUMENT; | 126 return MOJO_RESULT_INVALID_ARGUMENT; |
| 116 } | 127 } |
| 117 | 128 |
| 118 MojoResult Dispatcher::AddWaiterImplNoLock(Waiter* waiter, | 129 MojoResult Dispatcher::AddWaiterImplNoLock(Waiter* waiter, |
| 119 MojoWaitFlags flags, | 130 MojoWaitFlags flags, |
| 120 MojoResult wake_result) { | 131 MojoResult wake_result) { |
| 121 lock_.AssertAcquired(); | 132 lock_.AssertAcquired(); |
| 122 DCHECK(!is_closed_); | 133 DCHECK(!is_closed_); |
| 123 // By default, waiting isn't supported. Only dispatchers that can be waited on | 134 // By default, waiting isn't supported. Only dispatchers that can be waited on |
| 124 // will do something nontrivial. | 135 // will do something nontrivial. |
| 125 return MOJO_RESULT_FAILED_PRECONDITION; | 136 return MOJO_RESULT_FAILED_PRECONDITION; |
| 126 } | 137 } |
| 127 | 138 |
| 128 void Dispatcher::RemoveWaiterImplNoLock(Waiter* waiter) { | 139 void Dispatcher::RemoveWaiterImplNoLock(Waiter* waiter) { |
| 129 lock_.AssertAcquired(); | 140 lock_.AssertAcquired(); |
| 130 DCHECK(!is_closed_); | 141 DCHECK(!is_closed_); |
| 131 // By default, waiting isn't supported. Only dispatchers that can be waited on | 142 // By default, waiting isn't supported. Only dispatchers that can be waited on |
| 132 // will do something nontrivial. | 143 // will do something nontrivial. |
| 133 } | 144 } |
| 134 | 145 |
| 135 } // namespace system | 146 } // namespace system |
| 136 } // namespace mojo | 147 } // namespace mojo |
| OLD | NEW |