| 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 239 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 250 // bool ok = ShareToProcess(process, new_handle); | 250 // bool ok = ShareToProcess(process, new_handle); |
| 251 // Close(); | 251 // Close(); |
| 252 // return ok; | 252 // return ok; |
| 253 // Note that the memory is unmapped by calling this method, regardless of the | 253 // Note that the memory is unmapped by calling this method, regardless of the |
| 254 // return value. | 254 // return value. |
| 255 bool GiveToProcess(ProcessHandle process, | 255 bool GiveToProcess(ProcessHandle process, |
| 256 SharedMemoryHandle* new_handle) { | 256 SharedMemoryHandle* new_handle) { |
| 257 return ShareToProcessCommon(process, new_handle, true, SHARE_CURRENT_MODE); | 257 return ShareToProcessCommon(process, new_handle, true, SHARE_CURRENT_MODE); |
| 258 } | 258 } |
| 259 | 259 |
| 260 // DEPRECATED (crbug.com/345734): | |
| 261 // Locks the shared memory. | |
| 262 // | |
| 263 // WARNING: on POSIX the memory locking primitive only works across | |
| 264 // processes, not across threads. The LockDeprecated method is not currently | |
| 265 // used in inner loops, so we protect against multiple threads in a | |
| 266 // critical section using a class global lock. | |
| 267 void LockDeprecated(); | |
| 268 | |
| 269 // DEPRECATED (crbug.com/345734): | |
| 270 // Releases the shared memory lock. | |
| 271 void UnlockDeprecated(); | |
| 272 | |
| 273 private: | 260 private: |
| 274 #if defined(OS_POSIX) && !defined(OS_NACL) | 261 #if defined(OS_POSIX) && !defined(OS_NACL) && !defined(OS_ANDROID) |
| 275 #if !defined(OS_ANDROID) | |
| 276 bool PrepareMapFile(ScopedFILE fp, ScopedFD readonly); | 262 bool PrepareMapFile(ScopedFILE fp, ScopedFD readonly); |
| 277 bool FilePathForMemoryName(const std::string& mem_name, FilePath* path); | 263 bool FilePathForMemoryName(const std::string& mem_name, FilePath* path); |
| 278 #endif | 264 #endif // defined(OS_POSIX) && !defined(OS_NACL) && !defined(OS_ANDROID) |
| 279 void LockOrUnlockCommon(int function); | |
| 280 #endif // defined(OS_POSIX) && !defined(OS_NACL) | |
| 281 enum ShareMode { | 265 enum ShareMode { |
| 282 SHARE_READONLY, | 266 SHARE_READONLY, |
| 283 SHARE_CURRENT_MODE, | 267 SHARE_CURRENT_MODE, |
| 284 }; | 268 }; |
| 285 bool ShareToProcessCommon(ProcessHandle process, | 269 bool ShareToProcessCommon(ProcessHandle process, |
| 286 SharedMemoryHandle* new_handle, | 270 SharedMemoryHandle* new_handle, |
| 287 bool close_self, | 271 bool close_self, |
| 288 ShareMode); | 272 ShareMode); |
| 289 | 273 |
| 290 #if defined(OS_WIN) | 274 #if defined(OS_WIN) |
| 291 std::wstring name_; | 275 std::wstring name_; |
| 292 HANDLE mapped_file_; | 276 HANDLE mapped_file_; |
| 293 #elif defined(OS_POSIX) | 277 #elif defined(OS_POSIX) |
| 294 int mapped_file_; | 278 int mapped_file_; |
| 295 int readonly_mapped_file_; | 279 int readonly_mapped_file_; |
| 296 #endif | 280 #endif |
| 297 size_t mapped_size_; | 281 size_t mapped_size_; |
| 298 void* memory_; | 282 void* memory_; |
| 299 bool read_only_; | 283 bool read_only_; |
| 300 size_t requested_size_; | 284 size_t requested_size_; |
| 301 #if !defined(OS_POSIX) | |
| 302 HANDLE lock_; | |
| 303 #endif | |
| 304 | 285 |
| 305 DISALLOW_COPY_AND_ASSIGN(SharedMemory); | 286 DISALLOW_COPY_AND_ASSIGN(SharedMemory); |
| 306 }; | 287 }; |
| 307 | |
| 308 // DEPRECATED (crbug.com/345734): | |
| 309 // A helper class that acquires the shared memory lock while | |
| 310 // the SharedMemoryAutoLockDeprecated is in scope. | |
| 311 class SharedMemoryAutoLockDeprecated { | |
| 312 public: | |
| 313 explicit SharedMemoryAutoLockDeprecated(SharedMemory* shared_memory) | |
| 314 : shared_memory_(shared_memory) { | |
| 315 shared_memory_->LockDeprecated(); | |
| 316 } | |
| 317 | |
| 318 ~SharedMemoryAutoLockDeprecated() { | |
| 319 shared_memory_->UnlockDeprecated(); | |
| 320 } | |
| 321 | |
| 322 private: | |
| 323 SharedMemory* shared_memory_; | |
| 324 DISALLOW_COPY_AND_ASSIGN(SharedMemoryAutoLockDeprecated); | |
| 325 }; | |
| 326 | |
| 327 } // namespace base | 288 } // namespace base |
| 328 | 289 |
| 329 #endif // BASE_MEMORY_SHARED_MEMORY_H_ | 290 #endif // BASE_MEMORY_SHARED_MEMORY_H_ |
| OLD | NEW |