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/edk/system/data_pipe.h" | 5 #include "mojo/edk/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 242 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
253 DVLOG_IF(2, consumer_in_two_phase_read_no_lock()) | 253 DVLOG_IF(2, consumer_in_two_phase_read_no_lock()) |
254 << "Consumer closed with active two-phase read"; | 254 << "Consumer closed with active two-phase read"; |
255 consumer_two_phase_max_num_bytes_read_ = 0; | 255 consumer_two_phase_max_num_bytes_read_ = 0; |
256 ConsumerCloseImplNoLock(); | 256 ConsumerCloseImplNoLock(); |
257 AwakeProducerWaitersForStateChangeNoLock( | 257 AwakeProducerWaitersForStateChangeNoLock( |
258 ProducerGetHandleSignalsStateImplNoLock()); | 258 ProducerGetHandleSignalsStateImplNoLock()); |
259 } | 259 } |
260 | 260 |
261 MojoResult DataPipe::ConsumerReadData(UserPointer<void> elements, | 261 MojoResult DataPipe::ConsumerReadData(UserPointer<void> elements, |
262 UserPointer<uint32_t> num_bytes, | 262 UserPointer<uint32_t> num_bytes, |
263 bool all_or_none) { | 263 bool all_or_none, |
| 264 bool peek) { |
264 base::AutoLock locker(lock_); | 265 base::AutoLock locker(lock_); |
265 DCHECK(has_local_consumer_no_lock()); | 266 DCHECK(has_local_consumer_no_lock()); |
266 | 267 |
267 if (consumer_in_two_phase_read_no_lock()) | 268 if (consumer_in_two_phase_read_no_lock()) |
268 return MOJO_RESULT_BUSY; | 269 return MOJO_RESULT_BUSY; |
269 | 270 |
270 uint32_t max_num_bytes_to_read = num_bytes.Get(); | 271 uint32_t max_num_bytes_to_read = num_bytes.Get(); |
271 if (max_num_bytes_to_read % element_num_bytes_ != 0) | 272 if (max_num_bytes_to_read % element_num_bytes_ != 0) |
272 return MOJO_RESULT_INVALID_ARGUMENT; | 273 return MOJO_RESULT_INVALID_ARGUMENT; |
273 | 274 |
274 if (max_num_bytes_to_read == 0) | 275 if (max_num_bytes_to_read == 0) |
275 return MOJO_RESULT_OK; // Nothing to do. | 276 return MOJO_RESULT_OK; // Nothing to do. |
276 | 277 |
277 uint32_t min_num_bytes_to_read = all_or_none ? max_num_bytes_to_read : 0; | 278 uint32_t min_num_bytes_to_read = all_or_none ? max_num_bytes_to_read : 0; |
278 | 279 |
279 HandleSignalsState old_producer_state = | 280 HandleSignalsState old_producer_state = |
280 ProducerGetHandleSignalsStateImplNoLock(); | 281 ProducerGetHandleSignalsStateImplNoLock(); |
281 MojoResult rv = ConsumerReadDataImplNoLock( | 282 MojoResult rv = ConsumerReadDataImplNoLock( |
282 elements, num_bytes, max_num_bytes_to_read, min_num_bytes_to_read); | 283 elements, num_bytes, max_num_bytes_to_read, min_num_bytes_to_read, peek); |
283 HandleSignalsState new_producer_state = | 284 HandleSignalsState new_producer_state = |
284 ProducerGetHandleSignalsStateImplNoLock(); | 285 ProducerGetHandleSignalsStateImplNoLock(); |
285 if (!new_producer_state.equals(old_producer_state)) | 286 if (!new_producer_state.equals(old_producer_state)) |
286 AwakeProducerWaitersForStateChangeNoLock(new_producer_state); | 287 AwakeProducerWaitersForStateChangeNoLock(new_producer_state); |
287 return rv; | 288 return rv; |
288 } | 289 } |
289 | 290 |
290 MojoResult DataPipe::ConsumerDiscardData(UserPointer<uint32_t> num_bytes, | 291 MojoResult DataPipe::ConsumerDiscardData(UserPointer<uint32_t> num_bytes, |
291 bool all_or_none) { | 292 bool all_or_none) { |
292 base::AutoLock locker(lock_); | 293 base::AutoLock locker(lock_); |
(...skipping 171 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
464 void DataPipe::AwakeConsumerWaitersForStateChangeNoLock( | 465 void DataPipe::AwakeConsumerWaitersForStateChangeNoLock( |
465 const HandleSignalsState& new_consumer_state) { | 466 const HandleSignalsState& new_consumer_state) { |
466 lock_.AssertAcquired(); | 467 lock_.AssertAcquired(); |
467 if (!has_local_consumer_no_lock()) | 468 if (!has_local_consumer_no_lock()) |
468 return; | 469 return; |
469 consumer_waiter_list_->AwakeWaitersForStateChange(new_consumer_state); | 470 consumer_waiter_list_->AwakeWaitersForStateChange(new_consumer_state); |
470 } | 471 } |
471 | 472 |
472 } // namespace system | 473 } // namespace system |
473 } // namespace mojo | 474 } // namespace mojo |
OLD | NEW |