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, |
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_) |
59 return MOJO_RESULT_INVALID_ARGUMENT; | 60 return MOJO_RESULT_INVALID_ARGUMENT; |
60 | 61 |
61 return AddWaiterImplNoLock(waiter, flags, wake_result); | 62 return AddWaiterImplNoLock(waiter, flags, wake_result); |
62 } | 63 } |
63 | 64 |
64 void Dispatcher::RemoveWaiter(Waiter* waiter) { | 65 void Dispatcher::RemoveWaiter(Waiter* waiter) { |
65 base::AutoLock locker(lock_); | 66 base::AutoLock locker(lock_); |
66 if (is_closed_) | 67 if (is_closed_) |
67 return; | 68 return; |
68 RemoveWaiterImplNoLock(waiter); | 69 RemoveWaiterImplNoLock(waiter); |
69 } | 70 } |
70 | 71 |
| 72 scoped_refptr<Dispatcher> |
| 73 Dispatcher::CreateEquivalentDispatcherAndCloseNoLock() { |
| 74 lock_.AssertAcquired(); |
| 75 DCHECK(!is_closed_); |
| 76 |
| 77 is_closed_ = true; |
| 78 CancelAllWaitersNoLock(); |
| 79 return CreateEquivalentDispatcherAndCloseImplNoLock(); |
| 80 } |
| 81 |
71 Dispatcher::Dispatcher() | 82 Dispatcher::Dispatcher() |
72 : is_closed_(false) { | 83 : is_closed_(false) { |
73 } | 84 } |
74 | 85 |
75 Dispatcher::~Dispatcher() { | 86 Dispatcher::~Dispatcher() { |
76 // Make sure that |Close()| was called. | 87 // Make sure that |Close()| was called. |
77 DCHECK(is_closed_); | 88 DCHECK(is_closed_); |
78 } | 89 } |
79 | 90 |
80 void Dispatcher::CancelAllWaitersNoLock() { | 91 void Dispatcher::CancelAllWaitersNoLock() { |
(...skipping 16 matching lines...) Expand all Loading... |
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 |