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

Side by Side Diff: mojo/system/memory.h

Issue 417113010: Convert ReadData...() to use the new user pointer handling (see r285350). (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 5 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 | Annotate | Revision Log
« no previous file with comments | « mojo/system/local_data_pipe_unittest.cc ('k') | no next file » | 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 #ifndef MOJO_SYSTEM_MEMORY_H_ 5 #ifndef MOJO_SYSTEM_MEMORY_H_
6 #define MOJO_SYSTEM_MEMORY_H_ 6 #define MOJO_SYSTEM_MEMORY_H_
7 7
8 #include <stddef.h> 8 #include <stddef.h>
9 #include <stdint.h> 9 #include <stdint.h>
10 #include <string.h> // For |memcpy()|. 10 #include <string.h> // For |memcpy()|.
(...skipping 163 matching lines...) Expand 10 before | Expand all | Expand 10 after
174 // |memcpy(user_pointer, source, count * sizeof(Type))|. 174 // |memcpy(user_pointer, source, count * sizeof(Type))|.
175 // 175 //
176 // Note: The same comments about the validity of |Put()| (except for the part 176 // Note: The same comments about the validity of |Put()| (except for the part
177 // about |void|) apply here. 177 // about |void|) apply here.
178 void PutArray(const Type* source, size_t count) { 178 void PutArray(const Type* source, size_t count) {
179 internal::CheckUserPointerWithCountHelper< 179 internal::CheckUserPointerWithCountHelper<
180 sizeof(NonVoidType), MOJO_ALIGNOF(NonVoidType)>(pointer_, count); 180 sizeof(NonVoidType), MOJO_ALIGNOF(NonVoidType)>(pointer_, count);
181 memcpy(pointer_, source, count * sizeof(NonVoidType)); 181 memcpy(pointer_, source, count * sizeof(NonVoidType));
182 } 182 }
183 183
184 // Gets a |UserPointer| at offset |i| (in |Type|s) relative to this. This 184 // Gets a |UserPointer| at offset |i| (in |Type|s) relative to this.
185 // method is not valid if |Type| is |void| (TODO(vtl): Maybe I should make it
186 // valid, with the offset in bytes?).
187 UserPointer At(size_t i) const { 185 UserPointer At(size_t i) const {
188 return UserPointer(pointer_ + i); 186 return UserPointer(static_cast<Type*>(
187 static_cast<NonVoidType*>(pointer_) + i));
189 } 188 }
190 189
191 // TODO(vtl): This is temporary. Get rid of this. (We should pass 190 // TODO(vtl): This is temporary. Get rid of this. (We should pass
192 // |UserPointer<>|s along appropriately, or access data in a safe way 191 // |UserPointer<>|s along appropriately, or access data in a safe way
193 // everywhere.) 192 // everywhere.)
194 Type* GetPointerUnsafe() const { 193 Type* GetPointerUnsafe() const {
195 return pointer_; 194 return pointer_;
196 } 195 }
197 196
198 // These provides safe (read-only/write-only/read-and-write) access to a 197 // These provides safe (read-only/write-only/read-and-write) access to a
(...skipping 158 matching lines...) Expand 10 before | Expand all | Expand 10 after
357 // Provides a convenient way to make a |UserPointerValue<Type>|. 356 // Provides a convenient way to make a |UserPointerValue<Type>|.
358 template <typename Type> 357 template <typename Type>
359 inline UserPointerValue<Type> MakeUserPointerValue(Type* pointer) { 358 inline UserPointerValue<Type> MakeUserPointerValue(Type* pointer) {
360 return UserPointerValue<Type>(pointer); 359 return UserPointerValue<Type>(pointer);
361 } 360 }
362 361
363 } // namespace system 362 } // namespace system
364 } // namespace mojo 363 } // namespace mojo
365 364
366 #endif // MOJO_SYSTEM_MEMORY_H_ 365 #endif // MOJO_SYSTEM_MEMORY_H_
OLDNEW
« no previous file with comments | « mojo/system/local_data_pipe_unittest.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698