Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(222)

Side by Side Diff: mojo/edk/system/data_pipe_consumer_dispatcher.cc

Issue 1856113002: EDK: Add implementation of data pipe consumer read threshold stuff. (Closed) Base URL: https://github.com/domokit/mojo.git@master
Patch Set: Created 4 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « mojo/edk/system/data_pipe_consumer_dispatcher.h ('k') | mojo/edk/system/data_pipe_impl.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 <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 DataPipeConsumerDispatcher::Init(RefPtr<DataPipe>&& data_pipe) { 21 void DataPipeConsumerDispatcher::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
67 68
68 RefPtr<Dispatcher> 69 RefPtr<Dispatcher>
69 DataPipeConsumerDispatcher::CreateEquivalentDispatcherAndCloseImplNoLock() { 70 DataPipeConsumerDispatcher::CreateEquivalentDispatcherAndCloseImplNoLock() {
70 mutex().AssertHeld(); 71 mutex().AssertHeld();
71 72
72 auto dispatcher = DataPipeConsumerDispatcher::Create(); 73 auto dispatcher = DataPipeConsumerDispatcher::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 DataPipeConsumerDispatcher::SetDataPipeConsumerOptionsImplNoLock(
79 UserPointer<const MojoDataPipeConsumerOptions> options) {
80 mutex().AssertHeld();
81
82 UserOptionsReader<MojoDataPipeConsumerOptions> reader(options);
83 if (!reader.is_valid())
84 return MOJO_RESULT_INVALID_ARGUMENT;
85
86 if (!OPTIONS_STRUCT_HAS_MEMBER(MojoDataPipeConsumerOptions,
87 read_threshold_num_bytes, reader))
88 return MOJO_RESULT_OK;
89
90 return data_pipe_->ConsumerSetOptions(
91 reader.options().read_threshold_num_bytes);
92 }
93
94 MojoResult DataPipeConsumerDispatcher::GetDataPipeConsumerOptionsImplNoLock(
95 UserPointer<MojoDataPipeConsumerOptions> options,
96 uint32_t options_num_bytes) {
97 mutex().AssertHeld();
98
99 // Note: If/when |MojoDataPipeConsumerOptions| is extended beyond its initial
100 // definition, more work will be necessary. (See the definition of
101 // |MojoGetDataPipeConsumerOptions()| in mojo/public/c/system/data_pipe.h.)
102 static_assert(sizeof(MojoDataPipeConsumerOptions) == 8u,
103 "MojoDataPipeConsumerOptions has been extended!");
104
105 if (options_num_bytes < sizeof(MojoDataPipeConsumerOptions))
106 return MOJO_RESULT_INVALID_ARGUMENT;
107
108 uint32_t read_threshold_num_bytes = 0;
109 data_pipe_->ConsumerGetOptions(&read_threshold_num_bytes);
110 MojoDataPipeConsumerOptions model_options = {
111 sizeof(MojoDataPipeConsumerOptions), // |struct_size|.
112 read_threshold_num_bytes, // |read_threshold_num_bytes|.
113 };
114 options.Put(model_options);
115 return MOJO_RESULT_OK;
116 }
117
77 MojoResult DataPipeConsumerDispatcher::ReadDataImplNoLock( 118 MojoResult DataPipeConsumerDispatcher::ReadDataImplNoLock(
78 UserPointer<void> elements, 119 UserPointer<void> elements,
79 UserPointer<uint32_t> num_bytes, 120 UserPointer<uint32_t> num_bytes,
80 MojoReadDataFlags flags) { 121 MojoReadDataFlags flags) {
81 mutex().AssertHeld(); 122 mutex().AssertHeld();
82 123
83 if ((flags & MOJO_READ_DATA_FLAG_DISCARD)) { 124 if ((flags & MOJO_READ_DATA_FLAG_DISCARD)) {
84 // These flags are mutally exclusive. 125 // These flags are mutally exclusive.
85 if ((flags & MOJO_READ_DATA_FLAG_QUERY) || 126 if ((flags & MOJO_READ_DATA_FLAG_QUERY) ||
86 (flags & MOJO_READ_DATA_FLAG_PEEK)) 127 (flags & MOJO_READ_DATA_FLAG_PEEK))
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after
171 return rv; 212 return rv;
172 } 213 }
173 214
174 bool DataPipeConsumerDispatcher::IsBusyNoLock() const { 215 bool DataPipeConsumerDispatcher::IsBusyNoLock() const {
175 mutex().AssertHeld(); 216 mutex().AssertHeld();
176 return data_pipe_->ConsumerIsBusy(); 217 return data_pipe_->ConsumerIsBusy();
177 } 218 }
178 219
179 } // namespace system 220 } // namespace system
180 } // namespace mojo 221 } // namespace mojo
OLDNEW
« no previous file with comments | « mojo/edk/system/data_pipe_consumer_dispatcher.h ('k') | mojo/edk/system/data_pipe_impl.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698