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_consumer_dispatcher.h" | 5 #include "mojo/edk/system/data_pipe_consumer_dispatcher.h" |
6 | 6 |
7 #include "base/logging.h" | 7 #include "base/logging.h" |
8 #include "mojo/edk/system/data_pipe.h" | 8 #include "mojo/edk/system/data_pipe.h" |
9 #include "mojo/edk/system/memory.h" | 9 #include "mojo/edk/system/memory.h" |
10 | 10 |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
51 } | 51 } |
52 | 52 |
53 MojoResult DataPipeConsumerDispatcher::ReadDataImplNoLock( | 53 MojoResult DataPipeConsumerDispatcher::ReadDataImplNoLock( |
54 UserPointer<void> elements, | 54 UserPointer<void> elements, |
55 UserPointer<uint32_t> num_bytes, | 55 UserPointer<uint32_t> num_bytes, |
56 MojoReadDataFlags flags) { | 56 MojoReadDataFlags flags) { |
57 lock().AssertAcquired(); | 57 lock().AssertAcquired(); |
58 | 58 |
59 if ((flags & MOJO_READ_DATA_FLAG_DISCARD)) { | 59 if ((flags & MOJO_READ_DATA_FLAG_DISCARD)) { |
60 // These flags are mutally exclusive. | 60 // These flags are mutally exclusive. |
61 if ((flags & MOJO_READ_DATA_FLAG_QUERY)) | 61 if ((flags & MOJO_READ_DATA_FLAG_QUERY) || |
| 62 (flags & MOJO_READ_DATA_FLAG_PEEK)) |
62 return MOJO_RESULT_INVALID_ARGUMENT; | 63 return MOJO_RESULT_INVALID_ARGUMENT; |
63 DVLOG_IF(2, !elements.IsNull()) | 64 DVLOG_IF(2, !elements.IsNull()) |
64 << "Discard mode: ignoring non-null |elements|"; | 65 << "Discard mode: ignoring non-null |elements|"; |
65 return data_pipe_->ConsumerDiscardData( | 66 return data_pipe_->ConsumerDiscardData( |
66 num_bytes, (flags & MOJO_READ_DATA_FLAG_ALL_OR_NONE)); | 67 num_bytes, (flags & MOJO_READ_DATA_FLAG_ALL_OR_NONE)); |
67 } | 68 } |
68 | 69 |
69 if ((flags & MOJO_READ_DATA_FLAG_QUERY)) { | 70 if ((flags & MOJO_READ_DATA_FLAG_QUERY)) { |
| 71 if ((flags & MOJO_READ_DATA_FLAG_PEEK)) |
| 72 return MOJO_RESULT_INVALID_ARGUMENT; |
70 DCHECK(!(flags & MOJO_READ_DATA_FLAG_DISCARD)); // Handled above. | 73 DCHECK(!(flags & MOJO_READ_DATA_FLAG_DISCARD)); // Handled above. |
71 DVLOG_IF(2, !elements.IsNull()) | 74 DVLOG_IF(2, !elements.IsNull()) |
72 << "Query mode: ignoring non-null |elements|"; | 75 << "Query mode: ignoring non-null |elements|"; |
73 return data_pipe_->ConsumerQueryData(num_bytes); | 76 return data_pipe_->ConsumerQueryData(num_bytes); |
74 } | 77 } |
75 | 78 |
76 return data_pipe_->ConsumerReadData( | 79 return data_pipe_->ConsumerReadData( |
77 elements, num_bytes, (flags & MOJO_READ_DATA_FLAG_ALL_OR_NONE)); | 80 elements, |
| 81 num_bytes, |
| 82 !!(flags & MOJO_READ_DATA_FLAG_ALL_OR_NONE), |
| 83 !!(flags & MOJO_READ_DATA_FLAG_PEEK)); |
78 } | 84 } |
79 | 85 |
80 MojoResult DataPipeConsumerDispatcher::BeginReadDataImplNoLock( | 86 MojoResult DataPipeConsumerDispatcher::BeginReadDataImplNoLock( |
81 UserPointer<const void*> buffer, | 87 UserPointer<const void*> buffer, |
82 UserPointer<uint32_t> buffer_num_bytes, | 88 UserPointer<uint32_t> buffer_num_bytes, |
83 MojoReadDataFlags flags) { | 89 MojoReadDataFlags flags) { |
84 lock().AssertAcquired(); | 90 lock().AssertAcquired(); |
85 | 91 |
86 // These flags may not be used in two-phase mode. | 92 // These flags may not be used in two-phase mode. |
87 if ((flags & MOJO_READ_DATA_FLAG_DISCARD) || | 93 if ((flags & MOJO_READ_DATA_FLAG_DISCARD) || |
88 (flags & MOJO_READ_DATA_FLAG_QUERY)) | 94 (flags & MOJO_READ_DATA_FLAG_QUERY) || |
| 95 (flags & MOJO_READ_DATA_FLAG_PEEK)) |
89 return MOJO_RESULT_INVALID_ARGUMENT; | 96 return MOJO_RESULT_INVALID_ARGUMENT; |
90 | 97 |
91 return data_pipe_->ConsumerBeginReadData( | 98 return data_pipe_->ConsumerBeginReadData( |
92 buffer, buffer_num_bytes, (flags & MOJO_READ_DATA_FLAG_ALL_OR_NONE)); | 99 buffer, buffer_num_bytes, (flags & MOJO_READ_DATA_FLAG_ALL_OR_NONE)); |
93 } | 100 } |
94 | 101 |
95 MojoResult DataPipeConsumerDispatcher::EndReadDataImplNoLock( | 102 MojoResult DataPipeConsumerDispatcher::EndReadDataImplNoLock( |
96 uint32_t num_bytes_read) { | 103 uint32_t num_bytes_read) { |
97 lock().AssertAcquired(); | 104 lock().AssertAcquired(); |
98 | 105 |
(...skipping 22 matching lines...) Expand all Loading... |
121 data_pipe_->ConsumerRemoveWaiter(waiter, signals_state); | 128 data_pipe_->ConsumerRemoveWaiter(waiter, signals_state); |
122 } | 129 } |
123 | 130 |
124 bool DataPipeConsumerDispatcher::IsBusyNoLock() const { | 131 bool DataPipeConsumerDispatcher::IsBusyNoLock() const { |
125 lock().AssertAcquired(); | 132 lock().AssertAcquired(); |
126 return data_pipe_->ConsumerIsBusy(); | 133 return data_pipe_->ConsumerIsBusy(); |
127 } | 134 } |
128 | 135 |
129 } // namespace system | 136 } // namespace system |
130 } // namespace mojo | 137 } // namespace mojo |
OLD | NEW |