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

Side by Side Diff: base/memory/shared_memory_posix.cc

Issue 2496783002: gpu: Reuse existing code for shared memory allocation. (Closed)
Patch Set: . Created 4 years, 1 month 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 #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
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
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
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698