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

Side by Side Diff: base/memory/shared_memory.h

Issue 2535213002: [WIP] Add SharedMemoryTracker to dump base::SharedMemory usage
Patch Set: (rebase) Created 3 years, 7 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 | « base/memory/discardable_shared_memory.h ('k') | base/memory/shared_memory_handle.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 (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 BASE_MEMORY_SHARED_MEMORY_H_ 5 #ifndef BASE_MEMORY_SHARED_MEMORY_H_
6 #define BASE_MEMORY_SHARED_MEMORY_H_ 6 #define BASE_MEMORY_SHARED_MEMORY_H_
7 7
8 #include <stddef.h> 8 #include <stddef.h>
9 9
10 #include <string> 10 #include <string>
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after
120 // Duplicates The underlying OS primitive. Returns an invalid handle on 120 // Duplicates The underlying OS primitive. Returns an invalid handle on
121 // failure. The caller is responsible for destroying the duplicated OS 121 // failure. The caller is responsible for destroying the duplicated OS
122 // primitive. 122 // primitive.
123 static SharedMemoryHandle DuplicateHandle(const SharedMemoryHandle& handle); 123 static SharedMemoryHandle DuplicateHandle(const SharedMemoryHandle& handle);
124 124
125 #if defined(OS_POSIX) 125 #if defined(OS_POSIX)
126 // This method requires that the SharedMemoryHandle is backed by a POSIX fd. 126 // This method requires that the SharedMemoryHandle is backed by a POSIX fd.
127 static int GetFdFromSharedMemoryHandle(const SharedMemoryHandle& handle); 127 static int GetFdFromSharedMemoryHandle(const SharedMemoryHandle& handle);
128 #endif 128 #endif
129 129
130 int importance() const { return importance_; }
131 void set_importance(int importance) { importance_ = importance; }
132
130 // Creates a shared memory object as described by the options struct. 133 // Creates a shared memory object as described by the options struct.
131 // Returns true on success and false on failure. 134 // Returns true on success and false on failure.
132 bool Create(const SharedMemoryCreateOptions& options); 135 bool Create(const SharedMemoryCreateOptions& options);
133 136
134 // Creates and maps an anonymous shared memory segment of size size. 137 // Creates and maps an anonymous shared memory segment of size size.
135 // Returns true on success and false on failure. 138 // Returns true on success and false on failure.
136 bool CreateAndMapAnonymous(size_t size); 139 bool CreateAndMapAnonymous(size_t size);
137 140
138 // Creates an anonymous shared memory segment of size size. 141 // Creates an anonymous shared memory segment of size size.
139 // Returns true on success and false on failure. 142 // Returns true on success and false on failure.
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after
219 222
220 // Returns a read-only handle to this shared memory region. The caller takes 223 // Returns a read-only handle to this shared memory region. The caller takes
221 // ownership of the handle. For POSIX handles, CHECK-fails if the region 224 // ownership of the handle. For POSIX handles, CHECK-fails if the region
222 // wasn't Created or Opened with share_read_only=true, which is required to 225 // wasn't Created or Opened with share_read_only=true, which is required to
223 // make the handle read-only. When the handle is passed to the IPC subsystem, 226 // make the handle read-only. When the handle is passed to the IPC subsystem,
224 // that takes ownership of the handle. As such, it's not valid to pass the 227 // that takes ownership of the handle. As such, it's not valid to pass the
225 // sample handle to the IPC subsystem twice. Returns an invalid handle on 228 // sample handle to the IPC subsystem twice. Returns an invalid handle on
226 // failure. 229 // failure.
227 SharedMemoryHandle GetReadOnlyHandle(); 230 SharedMemoryHandle GetReadOnlyHandle();
228 231
229 #if defined(OS_POSIX) && (!defined(OS_MACOSX) || defined(OS_IOS)) && \
230 !defined(OS_NACL)
231 using UniqueId = std::pair<dev_t, ino_t>;
232
233 struct UniqueIdHash {
234 size_t operator()(const UniqueId& id) const {
235 return HashInts(id.first, id.second);
236 }
237 };
238
239 // Returns a unique ID for this shared memory's handle. Note this function may
240 // access file system and be slow.
241 bool GetUniqueId(UniqueId* id) const;
242 #endif
243
244 // Returns the last error encountered as a result of a call to Create() or 232 // Returns the last error encountered as a result of a call to Create() or
245 // Map(). Note: Currently only errors from Mac POSIX shared memory 233 // Map(). Note: Currently only errors from Mac POSIX shared memory
246 // implementation are fully instrumented. 234 // implementation are fully instrumented.
247 // TODO(asvitkine): Evaluate whether we want to keep this ability after 235 // TODO(asvitkine): Evaluate whether we want to keep this ability after
248 // crbug.com/703649 is fixed and expand to all platforms or remove. 236 // crbug.com/703649 is fixed and expand to all platforms or remove.
249 SharedMemoryError get_last_error() const { return last_error_; } 237 SharedMemoryError get_last_error() const { return last_error_; }
250 238
251 private: 239 private:
252 #if defined(OS_POSIX) && !defined(OS_NACL) && !defined(OS_ANDROID) && \ 240 #if defined(OS_POSIX) && !defined(OS_NACL) && !defined(OS_ANDROID) && \
253 (!defined(OS_MACOSX) || defined(OS_IOS)) 241 (!defined(OS_MACOSX) || defined(OS_IOS))
(...skipping 18 matching lines...) Expand all
272 #endif 260 #endif
273 261
274 // The OS primitive that backs the shared memory region. 262 // The OS primitive that backs the shared memory region.
275 SharedMemoryHandle shm_; 263 SharedMemoryHandle shm_;
276 264
277 size_t mapped_size_ = 0; 265 size_t mapped_size_ = 0;
278 void* memory_ = nullptr; 266 void* memory_ = nullptr;
279 bool read_only_ = false; 267 bool read_only_ = false;
280 size_t requested_size_ = 0; 268 size_t requested_size_ = 0;
281 SharedMemoryError last_error_ = SharedMemoryError::NO_ERRORS; 269 SharedMemoryError last_error_ = SharedMemoryError::NO_ERRORS;
270 int importance_ = 0;
282 271
283 DISALLOW_COPY_AND_ASSIGN(SharedMemory); 272 DISALLOW_COPY_AND_ASSIGN(SharedMemory);
284 }; 273 };
285 274
286 } // namespace base 275 } // namespace base
287 276
288 #endif // BASE_MEMORY_SHARED_MEMORY_H_ 277 #endif // BASE_MEMORY_SHARED_MEMORY_H_
OLDNEW
« no previous file with comments | « base/memory/discardable_shared_memory.h ('k') | base/memory/shared_memory_handle.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698