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

Side by Side Diff: base/shared_memory_posix.cc

Issue 19606: Unit test addition, cleanup for render_process/thread. (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 11 years, 11 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
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 <errno.h> 7 #include <errno.h>
8 #include <fcntl.h> 8 #include <fcntl.h>
9 #include <sys/mman.h> 9 #include <sys/mman.h>
10 10
(...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after
134 SharedMemoryHandle *new_handle, 134 SharedMemoryHandle *new_handle,
135 bool close_self) { 135 bool close_self) {
136 *new_handle = 0; 136 *new_handle = 0;
137 // TODO(awalker): figure out if we need this, and do the appropriate 137 // TODO(awalker): figure out if we need this, and do the appropriate
138 // VM magic if so. 138 // VM magic if so.
139 return false; 139 return false;
140 } 140 }
141 141
142 142
143 void SharedMemory::Close() { 143 void SharedMemory::Close() {
144 if (memory_ != NULL) {
145 munmap(memory_, max_size_);
146 144
147 memory_ = NULL; 145 Unmap();
148 max_size_ = 0;
149 }
150 146
151 std::string posix_name(WideToUTF8(name_)); 147 std::string posix_name(WideToUTF8(name_));
152 if (mapped_file_ > 0) { 148 if (mapped_file_ > 0) {
153 close(mapped_file_); 149 close(mapped_file_);
154 shm_unlink(posix_name.c_str()); 150 shm_unlink(posix_name.c_str());
155 mapped_file_ = -1; 151 mapped_file_ = -1;
156 } 152 }
157 153
158 if (lock_) { 154 if (lock_) {
159 posix_name += kSemaphoreSuffix; 155 posix_name += kSemaphoreSuffix;
160 sem_unlink(posix_name.c_str()); 156 sem_unlink(posix_name.c_str());
161 lock_ = NULL; 157 lock_ = NULL;
162 } 158 }
163 } 159 }
164 160
165 void SharedMemory::Lock() { 161 void SharedMemory::Lock() {
166 DCHECK(lock_ != NULL); 162 DCHECK(lock_ != NULL);
167 while(sem_wait(lock_) < 0) { 163 while(sem_wait(lock_) < 0) {
168 DCHECK(errno == EAGAIN || errno == EINTR); 164 DCHECK(errno == EAGAIN || errno == EINTR);
169 } 165 }
170 } 166 }
171 167
172 void SharedMemory::Unlock() { 168 void SharedMemory::Unlock() {
173 DCHECK(lock_ != NULL); 169 DCHECK(lock_ != NULL);
174 int result = sem_post(lock_); 170 int result = sem_post(lock_);
175 DCHECK(result == 0); 171 DCHECK(result == 0);
176 } 172 }
177 173
178 } // namespace base 174 } // namespace base
OLDNEW
« no previous file with comments | « no previous file | chrome/browser/net/url_fetcher_unittest.cc » ('j') | chrome/chrome.xcodeproj/project.pbxproj » ('J')

Powered by Google App Engine
This is Rietveld 408576698