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 #include "base/memory/shared_memory.h" | 5 #include "base/memory/shared_memory.h" |
6 | 6 |
7 #include <errno.h> | 7 #include <errno.h> |
8 #include <fcntl.h> | 8 #include <fcntl.h> |
9 #include <stddef.h> | 9 #include <stddef.h> |
10 #include <sys/mman.h> | 10 #include <sys/mman.h> |
(...skipping 361 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
372 munmap(memory_, mapped_size_); | 372 munmap(memory_, mapped_size_); |
373 memory_ = NULL; | 373 memory_ = NULL; |
374 mapped_size_ = 0; | 374 mapped_size_ = 0; |
375 return true; | 375 return true; |
376 } | 376 } |
377 | 377 |
378 SharedMemoryHandle SharedMemory::handle() const { | 378 SharedMemoryHandle SharedMemory::handle() const { |
379 return FileDescriptor(mapped_file_, false); | 379 return FileDescriptor(mapped_file_, false); |
380 } | 380 } |
381 | 381 |
| 382 SharedMemoryHandle SharedMemory::TakeHandle() { |
| 383 FileDescriptor handle(mapped_file_, true); |
| 384 mapped_file_ = -1; |
| 385 memory_ = nullptr; |
| 386 mapped_size_ = 0; |
| 387 return handle; |
| 388 } |
| 389 |
382 void SharedMemory::Close() { | 390 void SharedMemory::Close() { |
383 if (mapped_file_ > 0) { | 391 if (mapped_file_ > 0) { |
384 if (IGNORE_EINTR(close(mapped_file_)) < 0) | 392 if (IGNORE_EINTR(close(mapped_file_)) < 0) |
385 PLOG(ERROR) << "close"; | 393 PLOG(ERROR) << "close"; |
386 mapped_file_ = -1; | 394 mapped_file_ = -1; |
387 } | 395 } |
388 if (readonly_mapped_file_ > 0) { | 396 if (readonly_mapped_file_ > 0) { |
389 if (IGNORE_EINTR(close(readonly_mapped_file_)) < 0) | 397 if (IGNORE_EINTR(close(readonly_mapped_file_)) < 0) |
390 PLOG(ERROR) << "close"; | 398 PLOG(ERROR) << "close"; |
391 readonly_mapped_file_ = -1; | 399 readonly_mapped_file_ = -1; |
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
487 | 495 |
488 if (close_self) { | 496 if (close_self) { |
489 Unmap(); | 497 Unmap(); |
490 Close(); | 498 Close(); |
491 } | 499 } |
492 | 500 |
493 return true; | 501 return true; |
494 } | 502 } |
495 | 503 |
496 } // namespace base | 504 } // namespace base |
OLD | NEW |