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

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

Issue 2654073002: base: Introduce SharedMemoryTracker for POSIX (but not macOS) (Closed)
Patch Set: Use 1 bucket / actually no more bucket Created 3 years, 10 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
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 237 matching lines...) Expand 10 before | Expand all | Expand 10 after
248 // bool ok = ShareToProcess(process, new_handle); 248 // bool ok = ShareToProcess(process, new_handle);
249 // Close(); 249 // Close();
250 // return ok; 250 // return ok;
251 // Note that the memory is unmapped by calling this method, regardless of the 251 // Note that the memory is unmapped by calling this method, regardless of the
252 // return value. 252 // return value.
253 bool GiveToProcess(ProcessHandle process, 253 bool GiveToProcess(ProcessHandle process,
254 SharedMemoryHandle* new_handle) { 254 SharedMemoryHandle* new_handle) {
255 return ShareToProcessCommon(process, new_handle, true, SHARE_CURRENT_MODE); 255 return ShareToProcessCommon(process, new_handle, true, SHARE_CURRENT_MODE);
256 } 256 }
257 257
258 #if defined(OS_POSIX) && (!defined(OS_MACOSX) || defined(OS_IOS)) && \
259 !defined(OS_NACL)
260 using Id = std::pair<dev_t, ino_t>;
danakj 2017/02/24 15:30:28 one request, lets give this a more.. unique.. name
hajimehoshi 2017/02/27 07:51:54 Done.
261
262 struct IdHash {
263 size_t operator()(const Id& id) const {
264 return HashInts(id.first, id.second);
265 }
266 };
267
268 // Returns a unique ID for this shared memory's handle. Note this function may
269 // access file system and be slow.
270 bool GetUniqueId(Id* id) const;
271 #endif
272
258 private: 273 private:
259 #if defined(OS_POSIX) && !defined(OS_NACL) && !defined(OS_ANDROID) && \ 274 #if defined(OS_POSIX) && !defined(OS_NACL) && !defined(OS_ANDROID) && \
260 !(defined(OS_MACOSX) && !defined(OS_IOS)) 275 (!defined(OS_MACOSX) || defined(OS_IOS))
261 bool FilePathForMemoryName(const std::string& mem_name, FilePath* path); 276 bool FilePathForMemoryName(const std::string& mem_name, FilePath* path);
262 #endif 277 #endif
263 278
264 enum ShareMode { 279 enum ShareMode {
265 SHARE_READONLY, 280 SHARE_READONLY,
266 SHARE_CURRENT_MODE, 281 SHARE_CURRENT_MODE,
267 }; 282 };
268 283
269 #if defined(OS_MACOSX) 284 #if defined(OS_MACOSX)
270 bool Share(SharedMemoryHandle* new_handle, ShareMode share_mode); 285 bool Share(SharedMemoryHandle* new_handle, ShareMode share_mode);
(...skipping 23 matching lines...) Expand all
294 int mapped_file_; 309 int mapped_file_;
295 int readonly_mapped_file_; 310 int readonly_mapped_file_;
296 #endif 311 #endif
297 size_t mapped_size_; 312 size_t mapped_size_;
298 void* memory_; 313 void* memory_;
299 bool read_only_; 314 bool read_only_;
300 size_t requested_size_; 315 size_t requested_size_;
301 316
302 DISALLOW_COPY_AND_ASSIGN(SharedMemory); 317 DISALLOW_COPY_AND_ASSIGN(SharedMemory);
303 }; 318 };
319
304 } // namespace base 320 } // namespace base
305 321
306 #endif // BASE_MEMORY_SHARED_MEMORY_H_ 322 #endif // BASE_MEMORY_SHARED_MEMORY_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698