Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 "build/build_config.h" | 8 #include "build/build_config.h" |
| 9 | 9 |
| 10 #include <string> | 10 #include <string> |
| (...skipping 258 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 269 // bool ok = ShareToProcess(process, new_handle); | 269 // bool ok = ShareToProcess(process, new_handle); |
| 270 // Close(); | 270 // Close(); |
| 271 // return ok; | 271 // return ok; |
| 272 // Note that the memory is unmapped by calling this method, regardless of the | 272 // Note that the memory is unmapped by calling this method, regardless of the |
| 273 // return value. | 273 // return value. |
| 274 bool GiveToProcess(ProcessHandle process, | 274 bool GiveToProcess(ProcessHandle process, |
| 275 SharedMemoryHandle* new_handle) { | 275 SharedMemoryHandle* new_handle) { |
| 276 return ShareToProcessCommon(process, new_handle, true, SHARE_CURRENT_MODE); | 276 return ShareToProcessCommon(process, new_handle, true, SHARE_CURRENT_MODE); |
| 277 } | 277 } |
| 278 | 278 |
| 279 // DEPRECATED (crbug.com/345734): | |
| 280 // Locks the shared memory. | |
| 281 // | |
| 282 // WARNING: on POSIX the memory locking primitive only works across | |
| 283 // processes, not across threads. The LockDeprecated method is not currently | |
| 284 // used in inner loops, so we protect against multiple threads in a | |
| 285 // critical section using a class global lock. | |
| 286 void LockDeprecated(); | |
| 287 | |
| 288 // DEPRECATED (crbug.com/345734): | |
| 289 // Releases the shared memory lock. | |
| 290 void UnlockDeprecated(); | |
| 291 | |
| 292 private: | 279 private: |
| 293 #if defined(OS_POSIX) && !defined(OS_NACL) | 280 #if defined(OS_POSIX) && !defined(OS_NACL) && !defined(OS_ANDROID) |
| 294 #if !defined(OS_ANDROID) | |
| 295 bool PrepareMapFile(ScopedFILE fp, ScopedFD readonly); | 281 bool PrepareMapFile(ScopedFILE fp, ScopedFD readonly); |
| 296 bool FilePathForMemoryName(const std::string& mem_name, FilePath* path); | 282 bool FilePathForMemoryName(const std::string& mem_name, FilePath* path); |
| 297 #endif | 283 #endif // defined(OS_POSIX) && !defined(OS_NACL) && !defined(OS_ANDROID) |
| 298 void LockOrUnlockCommon(int function); | |
| 299 #endif // defined(OS_POSIX) && !defined(OS_NACL) | |
| 300 enum ShareMode { | 284 enum ShareMode { |
| 301 SHARE_READONLY, | 285 SHARE_READONLY, |
| 302 SHARE_CURRENT_MODE, | 286 SHARE_CURRENT_MODE, |
| 303 }; | 287 }; |
| 304 bool ShareToProcessCommon(ProcessHandle process, | 288 bool ShareToProcessCommon(ProcessHandle process, |
| 305 SharedMemoryHandle* new_handle, | 289 SharedMemoryHandle* new_handle, |
| 306 bool close_self, | 290 bool close_self, |
| 307 ShareMode); | 291 ShareMode); |
| 308 | 292 |
| 309 #if defined(OS_WIN) | 293 #if defined(OS_WIN) |
| 310 std::wstring name_; | 294 std::wstring name_; |
| 311 HANDLE mapped_file_; | 295 HANDLE mapped_file_; |
| 312 #elif defined(OS_POSIX) | 296 #elif defined(OS_POSIX) |
| 313 int mapped_file_; | 297 int mapped_file_; |
| 314 int readonly_mapped_file_; | 298 int readonly_mapped_file_; |
| 315 ino_t inode_; | 299 ino_t inode_; |
|
Nico
2015/06/11 15:39:18
didn't you delete this field yesterday? i guess th
erikchen
2015/06/11 17:36:30
Rebased the CL.
| |
| 316 #endif | 300 #endif |
| 317 size_t mapped_size_; | 301 size_t mapped_size_; |
| 318 void* memory_; | 302 void* memory_; |
| 319 bool read_only_; | 303 bool read_only_; |
| 320 size_t requested_size_; | 304 size_t requested_size_; |
| 321 #if !defined(OS_POSIX) | |
| 322 HANDLE lock_; | |
| 323 #endif | |
| 324 | 305 |
| 325 DISALLOW_COPY_AND_ASSIGN(SharedMemory); | 306 DISALLOW_COPY_AND_ASSIGN(SharedMemory); |
| 326 }; | 307 }; |
| 327 | |
| 328 // DEPRECATED (crbug.com/345734): | |
| 329 // A helper class that acquires the shared memory lock while | |
| 330 // the SharedMemoryAutoLockDeprecated is in scope. | |
| 331 class SharedMemoryAutoLockDeprecated { | |
| 332 public: | |
| 333 explicit SharedMemoryAutoLockDeprecated(SharedMemory* shared_memory) | |
| 334 : shared_memory_(shared_memory) { | |
| 335 shared_memory_->LockDeprecated(); | |
| 336 } | |
| 337 | |
| 338 ~SharedMemoryAutoLockDeprecated() { | |
| 339 shared_memory_->UnlockDeprecated(); | |
| 340 } | |
| 341 | |
| 342 private: | |
| 343 SharedMemory* shared_memory_; | |
| 344 DISALLOW_COPY_AND_ASSIGN(SharedMemoryAutoLockDeprecated); | |
| 345 }; | |
| 346 | |
| 347 } // namespace base | 308 } // namespace base |
| 348 | 309 |
| 349 #endif // BASE_MEMORY_SHARED_MEMORY_H_ | 310 #endif // BASE_MEMORY_SHARED_MEMORY_H_ |
| OLD | NEW |