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/data_pipe.h" | 5 #include "mojo/system/data_pipe.h" |
6 | 6 |
7 #include <string.h> | 7 #include <string.h> |
8 | 8 |
9 #include <algorithm> | 9 #include <algorithm> |
10 #include <limits> | 10 #include <limits> |
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
113 return MOJO_RESULT_OK; // Nothing to do. | 113 return MOJO_RESULT_OK; // Nothing to do. |
114 | 114 |
115 HandleSignalsState old_consumer_state = ConsumerGetHandleSignalsStateNoLock(); | 115 HandleSignalsState old_consumer_state = ConsumerGetHandleSignalsStateNoLock(); |
116 MojoResult rv = ProducerWriteDataImplNoLock(elements, num_bytes, all_or_none); | 116 MojoResult rv = ProducerWriteDataImplNoLock(elements, num_bytes, all_or_none); |
117 HandleSignalsState new_consumer_state = ConsumerGetHandleSignalsStateNoLock(); | 117 HandleSignalsState new_consumer_state = ConsumerGetHandleSignalsStateNoLock(); |
118 if (!new_consumer_state.equals(old_consumer_state)) | 118 if (!new_consumer_state.equals(old_consumer_state)) |
119 AwakeConsumerWaitersForStateChangeNoLock(new_consumer_state); | 119 AwakeConsumerWaitersForStateChangeNoLock(new_consumer_state); |
120 return rv; | 120 return rv; |
121 } | 121 } |
122 | 122 |
123 MojoResult DataPipe::ProducerBeginWriteData(void** buffer, | 123 MojoResult DataPipe::ProducerBeginWriteData( |
124 uint32_t* buffer_num_bytes, | 124 UserPointer<void*> buffer, |
125 bool all_or_none) { | 125 UserPointer<uint32_t> buffer_num_bytes, |
| 126 bool all_or_none) { |
126 base::AutoLock locker(lock_); | 127 base::AutoLock locker(lock_); |
127 DCHECK(has_local_producer_no_lock()); | 128 DCHECK(has_local_producer_no_lock()); |
128 | 129 |
129 if (producer_in_two_phase_write_no_lock()) | 130 if (producer_in_two_phase_write_no_lock()) |
130 return MOJO_RESULT_BUSY; | 131 return MOJO_RESULT_BUSY; |
131 if (!consumer_open_no_lock()) | 132 if (!consumer_open_no_lock()) |
132 return MOJO_RESULT_FAILED_PRECONDITION; | 133 return MOJO_RESULT_FAILED_PRECONDITION; |
133 | 134 |
134 if (all_or_none && *buffer_num_bytes % element_num_bytes_ != 0) | 135 uint32_t min_num_bytes_to_write = 0; |
135 return MOJO_RESULT_INVALID_ARGUMENT; | 136 if (all_or_none) { |
| 137 min_num_bytes_to_write = buffer_num_bytes.Get(); |
| 138 if (min_num_bytes_to_write % element_num_bytes_ != 0) |
| 139 return MOJO_RESULT_INVALID_ARGUMENT; |
| 140 } |
136 | 141 |
137 MojoResult rv = ProducerBeginWriteDataImplNoLock(buffer, buffer_num_bytes, | 142 MojoResult rv = ProducerBeginWriteDataImplNoLock(buffer, buffer_num_bytes, |
138 all_or_none); | 143 min_num_bytes_to_write); |
139 if (rv != MOJO_RESULT_OK) | 144 if (rv != MOJO_RESULT_OK) |
140 return rv; | 145 return rv; |
141 // Note: No need to awake producer waiters, even though we're going from | 146 // Note: No need to awake producer waiters, even though we're going from |
142 // writable to non-writable (since you can't wait on non-writability). | 147 // writable to non-writable (since you can't wait on non-writability). |
143 // Similarly, though this may have discarded data (in "may discard" mode), | 148 // Similarly, though this may have discarded data (in "may discard" mode), |
144 // making it non-readable, there's still no need to awake consumer waiters. | 149 // making it non-readable, there's still no need to awake consumer waiters. |
145 DCHECK(producer_in_two_phase_write_no_lock()); | 150 DCHECK(producer_in_two_phase_write_no_lock()); |
146 return MOJO_RESULT_OK; | 151 return MOJO_RESULT_OK; |
147 } | 152 } |
148 | 153 |
(...skipping 245 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
394 void DataPipe::AwakeConsumerWaitersForStateChangeNoLock( | 399 void DataPipe::AwakeConsumerWaitersForStateChangeNoLock( |
395 const HandleSignalsState& new_consumer_state) { | 400 const HandleSignalsState& new_consumer_state) { |
396 lock_.AssertAcquired(); | 401 lock_.AssertAcquired(); |
397 if (!has_local_consumer_no_lock()) | 402 if (!has_local_consumer_no_lock()) |
398 return; | 403 return; |
399 consumer_waiter_list_->AwakeWaitersForStateChange(new_consumer_state); | 404 consumer_waiter_list_->AwakeWaitersForStateChange(new_consumer_state); |
400 } | 405 } |
401 | 406 |
402 } // namespace system | 407 } // namespace system |
403 } // namespace mojo | 408 } // namespace mojo |
OLD | NEW |