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_producer_dispatcher.h" | 5 #include "mojo/edk/system/data_pipe_producer_dispatcher.h" |
6 | 6 |
7 #include <utility> | 7 #include <utility> |
8 | 8 |
9 #include "base/logging.h" | 9 #include "base/logging.h" |
10 #include "mojo/edk/system/data_pipe.h" | 10 #include "mojo/edk/system/data_pipe.h" |
11 #include "mojo/edk/system/memory.h" | 11 #include "mojo/edk/system/memory.h" |
| 12 #include "mojo/edk/system/options_validation.h" |
12 | 13 |
13 using mojo::platform::ScopedPlatformHandle; | 14 using mojo::platform::ScopedPlatformHandle; |
14 using mojo::util::MutexLocker; | 15 using mojo::util::MutexLocker; |
15 using mojo::util::RefPtr; | 16 using mojo::util::RefPtr; |
16 | 17 |
17 namespace mojo { | 18 namespace mojo { |
18 namespace system { | 19 namespace system { |
19 | 20 |
20 void DataPipeProducerDispatcher::Init(RefPtr<DataPipe>&& data_pipe) { | 21 void DataPipeProducerDispatcher::Init(RefPtr<DataPipe>&& data_pipe) { |
21 DCHECK(data_pipe); | 22 DCHECK(data_pipe); |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
67 | 68 |
68 RefPtr<Dispatcher> | 69 RefPtr<Dispatcher> |
69 DataPipeProducerDispatcher::CreateEquivalentDispatcherAndCloseImplNoLock() { | 70 DataPipeProducerDispatcher::CreateEquivalentDispatcherAndCloseImplNoLock() { |
70 mutex().AssertHeld(); | 71 mutex().AssertHeld(); |
71 | 72 |
72 auto dispatcher = DataPipeProducerDispatcher::Create(); | 73 auto dispatcher = DataPipeProducerDispatcher::Create(); |
73 dispatcher->Init(std::move(data_pipe_)); | 74 dispatcher->Init(std::move(data_pipe_)); |
74 return dispatcher; | 75 return dispatcher; |
75 } | 76 } |
76 | 77 |
| 78 MojoResult DataPipeProducerDispatcher::SetDataPipeProducerOptionsImplNoLock( |
| 79 UserPointer<const MojoDataPipeProducerOptions> options) { |
| 80 mutex().AssertHeld(); |
| 81 |
| 82 // The default of 0 means 1 element (however big that is). |
| 83 uint32_t write_threshold_num_bytes = 0; |
| 84 if (!options.IsNull()) { |
| 85 UserOptionsReader<MojoDataPipeProducerOptions> reader(options); |
| 86 if (!reader.is_valid()) |
| 87 return MOJO_RESULT_INVALID_ARGUMENT; |
| 88 |
| 89 if (!OPTIONS_STRUCT_HAS_MEMBER(MojoDataPipeProducerOptions, |
| 90 write_threshold_num_bytes, reader)) |
| 91 return MOJO_RESULT_OK; |
| 92 |
| 93 write_threshold_num_bytes = reader.options().write_threshold_num_bytes; |
| 94 } |
| 95 |
| 96 return data_pipe_->ProducerSetOptions(write_threshold_num_bytes); |
| 97 } |
| 98 |
| 99 MojoResult DataPipeProducerDispatcher::GetDataPipeProducerOptionsImplNoLock( |
| 100 UserPointer<MojoDataPipeProducerOptions> options, |
| 101 uint32_t options_num_bytes) { |
| 102 mutex().AssertHeld(); |
| 103 |
| 104 // Note: If/when |MojoDataPipeProducerOptions| is extended beyond its initial |
| 105 // definition, more work will be necessary. (See the definition of |
| 106 // |MojoGetDataPipeProducerOptions()| in mojo/public/c/system/data_pipe.h.) |
| 107 static_assert(sizeof(MojoDataPipeProducerOptions) == 8u, |
| 108 "MojoDataPipeProducerOptions has been extended!"); |
| 109 |
| 110 if (options_num_bytes < sizeof(MojoDataPipeProducerOptions)) |
| 111 return MOJO_RESULT_INVALID_ARGUMENT; |
| 112 |
| 113 uint32_t write_threshold_num_bytes = 0; |
| 114 data_pipe_->ProducerGetOptions(&write_threshold_num_bytes); |
| 115 MojoDataPipeProducerOptions model_options = { |
| 116 sizeof(MojoDataPipeProducerOptions), // |struct_size|. |
| 117 write_threshold_num_bytes, // |write_threshold_num_bytes|. |
| 118 }; |
| 119 options.Put(model_options); |
| 120 return MOJO_RESULT_OK; |
| 121 } |
| 122 |
77 MojoResult DataPipeProducerDispatcher::WriteDataImplNoLock( | 123 MojoResult DataPipeProducerDispatcher::WriteDataImplNoLock( |
78 UserPointer<const void> elements, | 124 UserPointer<const void> elements, |
79 UserPointer<uint32_t> num_bytes, | 125 UserPointer<uint32_t> num_bytes, |
80 MojoWriteDataFlags flags) { | 126 MojoWriteDataFlags flags) { |
81 mutex().AssertHeld(); | 127 mutex().AssertHeld(); |
82 return data_pipe_->ProducerWriteData( | 128 return data_pipe_->ProducerWriteData( |
83 elements, num_bytes, (flags & MOJO_WRITE_DATA_FLAG_ALL_OR_NONE)); | 129 elements, num_bytes, (flags & MOJO_WRITE_DATA_FLAG_ALL_OR_NONE)); |
84 } | 130 } |
85 | 131 |
86 MojoResult DataPipeProducerDispatcher::BeginWriteDataImplNoLock( | 132 MojoResult DataPipeProducerDispatcher::BeginWriteDataImplNoLock( |
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
147 return rv; | 193 return rv; |
148 } | 194 } |
149 | 195 |
150 bool DataPipeProducerDispatcher::IsBusyNoLock() const { | 196 bool DataPipeProducerDispatcher::IsBusyNoLock() const { |
151 mutex().AssertHeld(); | 197 mutex().AssertHeld(); |
152 return data_pipe_->ProducerIsBusy(); | 198 return data_pipe_->ProducerIsBusy(); |
153 } | 199 } |
154 | 200 |
155 } // namespace system | 201 } // namespace system |
156 } // namespace mojo | 202 } // namespace mojo |
OLD | NEW |