OLD | NEW |
1 // Copyright (c) 2011 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> |
(...skipping 322 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
333 return true; | 333 return true; |
334 } | 334 } |
335 | 335 |
336 void SharedMemory::LockOrUnlockCommon(int function) { | 336 void SharedMemory::LockOrUnlockCommon(int function) { |
337 DCHECK_GE(mapped_file_, 0); | 337 DCHECK_GE(mapped_file_, 0); |
338 while (lockf(mapped_file_, function, 0) < 0) { | 338 while (lockf(mapped_file_, function, 0) < 0) { |
339 if (errno == EINTR) { | 339 if (errno == EINTR) { |
340 continue; | 340 continue; |
341 } else if (errno == ENOLCK) { | 341 } else if (errno == ENOLCK) { |
342 // temporary kernel resource exaustion | 342 // temporary kernel resource exaustion |
343 base::PlatformThread::Sleep(500); | 343 base::PlatformThread::Sleep(base::TimeDelta::FromMilliseconds(500)); |
344 continue; | 344 continue; |
345 } else { | 345 } else { |
346 NOTREACHED() << "lockf() failed." | 346 NOTREACHED() << "lockf() failed." |
347 << " function:" << function | 347 << " function:" << function |
348 << " fd:" << mapped_file_ | 348 << " fd:" << mapped_file_ |
349 << " errno:" << errno | 349 << " errno:" << errno |
350 << " msg:" << safe_strerror(errno); | 350 << " msg:" << safe_strerror(errno); |
351 } | 351 } |
352 } | 352 } |
353 } | 353 } |
354 | 354 |
355 bool SharedMemory::ShareToProcessCommon(ProcessHandle process, | 355 bool SharedMemory::ShareToProcessCommon(ProcessHandle process, |
356 SharedMemoryHandle *new_handle, | 356 SharedMemoryHandle *new_handle, |
357 bool close_self) { | 357 bool close_self) { |
358 const int new_fd = dup(mapped_file_); | 358 const int new_fd = dup(mapped_file_); |
359 DCHECK_GE(new_fd, 0); | 359 DCHECK_GE(new_fd, 0); |
360 new_handle->fd = new_fd; | 360 new_handle->fd = new_fd; |
361 new_handle->auto_close = true; | 361 new_handle->auto_close = true; |
362 | 362 |
363 if (close_self) | 363 if (close_self) |
364 Close(); | 364 Close(); |
365 | 365 |
366 return true; | 366 return true; |
367 } | 367 } |
368 | 368 |
369 } // namespace base | 369 } // namespace base |
OLD | NEW |