| OLD | NEW |
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 #include <sys/stat.h> | 10 #include <sys/stat.h> |
| 11 #include <unistd.h> | 11 #include <unistd.h> |
| (...skipping 273 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 285 | 285 |
| 286 FilePath temp_dir; | 286 FilePath temp_dir; |
| 287 if (!file_util::GetShmemTempDir(&temp_dir)) | 287 if (!file_util::GetShmemTempDir(&temp_dir)) |
| 288 return false; | 288 return false; |
| 289 | 289 |
| 290 *path = temp_dir.AppendASCII("com.google.chrome.shmem." + mem_name); | 290 *path = temp_dir.AppendASCII("com.google.chrome.shmem." + mem_name); |
| 291 return true; | 291 return true; |
| 292 } | 292 } |
| 293 | 293 |
| 294 void SharedMemory::LockOrUnlockCommon(int function) { | 294 void SharedMemory::LockOrUnlockCommon(int function) { |
| 295 DCHECK(mapped_file_ >= 0); | 295 DCHECK_GE(mapped_file_, 0); |
| 296 while (lockf(mapped_file_, function, 0) < 0) { | 296 while (lockf(mapped_file_, function, 0) < 0) { |
| 297 if (errno == EINTR) { | 297 if (errno == EINTR) { |
| 298 continue; | 298 continue; |
| 299 } else if (errno == ENOLCK) { | 299 } else if (errno == ENOLCK) { |
| 300 // temporary kernel resource exaustion | 300 // temporary kernel resource exaustion |
| 301 base::PlatformThread::Sleep(500); | 301 base::PlatformThread::Sleep(500); |
| 302 continue; | 302 continue; |
| 303 } else { | 303 } else { |
| 304 NOTREACHED() << "lockf() failed." | 304 NOTREACHED() << "lockf() failed." |
| 305 << " function:" << function | 305 << " function:" << function |
| 306 << " fd:" << mapped_file_ | 306 << " fd:" << mapped_file_ |
| 307 << " errno:" << errno | 307 << " errno:" << errno |
| 308 << " msg:" << safe_strerror(errno); | 308 << " msg:" << safe_strerror(errno); |
| 309 } | 309 } |
| 310 } | 310 } |
| 311 } | 311 } |
| 312 | 312 |
| 313 bool SharedMemory::ShareToProcessCommon(ProcessHandle process, | 313 bool SharedMemory::ShareToProcessCommon(ProcessHandle process, |
| 314 SharedMemoryHandle *new_handle, | 314 SharedMemoryHandle *new_handle, |
| 315 bool close_self) { | 315 bool close_self) { |
| 316 const int new_fd = dup(mapped_file_); | 316 const int new_fd = dup(mapped_file_); |
| 317 DCHECK(new_fd >= 0); | 317 DCHECK_GE(new_fd, 0); |
| 318 new_handle->fd = new_fd; | 318 new_handle->fd = new_fd; |
| 319 new_handle->auto_close = true; | 319 new_handle->auto_close = true; |
| 320 | 320 |
| 321 if (close_self) | 321 if (close_self) |
| 322 Close(); | 322 Close(); |
| 323 | 323 |
| 324 return true; | 324 return true; |
| 325 } | 325 } |
| 326 | 326 |
| 327 } // namespace base | 327 } // namespace base |
| OLD | NEW |