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

Side by Side Diff: base/shared_memory_posix.cc

Issue 4039: ensure that the shared memory has actually been created before trying to re-u... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: Created 12 years, 3 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 | Annotate | Revision Log
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2006-2008 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/shared_memory.h" 5 #include "base/shared_memory.h"
6 6
7 #include <fcntl.h> 7 #include <fcntl.h>
8 #include <sys/mman.h> 8 #include <sys/mman.h>
9 9
10 #include "base/logging.h" 10 #include "base/logging.h"
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
49 if (lock_ != NULL) 49 if (lock_ != NULL)
50 sem_close(lock_); 50 sem_close(lock_);
51 } 51 }
52 52
53 bool SharedMemory::Create(const std::wstring &name, bool read_only, 53 bool SharedMemory::Create(const std::wstring &name, bool read_only,
54 bool open_existing, size_t size) { 54 bool open_existing, size_t size) {
55 read_only_ = read_only; 55 read_only_ = read_only;
56 56
57 int posix_flags = 0; 57 int posix_flags = 0;
58 posix_flags |= read_only ? O_RDONLY : O_RDWR; 58 posix_flags |= read_only ? O_RDONLY : O_RDWR;
59 if (!open_existing) 59 if (!open_existing || mapped_file_ <= 0)
60 posix_flags |= O_CREAT; 60 posix_flags |= O_CREAT;
61 61
62 if (CreateOrOpen(name, posix_flags)) { 62 if (CreateOrOpen(name, posix_flags)) {
63 ftruncate(mapped_file_, size); 63 ftruncate(mapped_file_, size);
64 max_size_ = size; 64 max_size_ = size;
65 return true; 65 return true;
66 } 66 }
67 67
68 return false; 68 return false;
69 } 69 }
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after
159 void SharedMemory::Lock() { 159 void SharedMemory::Lock() {
160 DCHECK(lock_ != NULL); 160 DCHECK(lock_ != NULL);
161 sem_wait(lock_); 161 sem_wait(lock_);
162 } 162 }
163 163
164 void SharedMemory::Unlock() { 164 void SharedMemory::Unlock() {
165 DCHECK(lock_ != NULL); 165 DCHECK(lock_ != NULL);
166 sem_post(lock_); 166 sem_post(lock_);
167 } 167 }
168 168
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698