OLD | NEW |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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> |
12 | 12 |
13 #include "base/file_util.h" | 13 #include "base/file_util.h" |
14 #include "base/logging.h" | 14 #include "base/logging.h" |
15 #include "base/platform_thread.h" | 15 #include "base/threading/platform_thread.h" |
16 #include "base/safe_strerror_posix.h" | 16 #include "base/safe_strerror_posix.h" |
17 #include "base/thread_restrictions.h" | 17 #include "base/thread_restrictions.h" |
18 #include "base/utf_string_conversions.h" | 18 #include "base/utf_string_conversions.h" |
19 | 19 |
20 namespace base { | 20 namespace base { |
21 | 21 |
22 namespace { | 22 namespace { |
23 // Paranoia. Semaphores and shared memory segments should live in different | 23 // Paranoia. Semaphores and shared memory segments should live in different |
24 // namespaces, but who knows what's out there. | 24 // namespaces, but who knows what's out there. |
25 const char kSemaphoreSuffix[] = "-sem"; | 25 const char kSemaphoreSuffix[] = "-sem"; |
(...skipping 266 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
292 } | 292 } |
293 } | 293 } |
294 | 294 |
295 void SharedMemory::LockOrUnlockCommon(int function) { | 295 void SharedMemory::LockOrUnlockCommon(int function) { |
296 DCHECK(mapped_file_ >= 0); | 296 DCHECK(mapped_file_ >= 0); |
297 while (lockf(mapped_file_, function, 0) < 0) { | 297 while (lockf(mapped_file_, function, 0) < 0) { |
298 if (errno == EINTR) { | 298 if (errno == EINTR) { |
299 continue; | 299 continue; |
300 } else if (errno == ENOLCK) { | 300 } else if (errno == ENOLCK) { |
301 // temporary kernel resource exaustion | 301 // temporary kernel resource exaustion |
302 PlatformThread::Sleep(500); | 302 base::PlatformThread::Sleep(500); |
303 continue; | 303 continue; |
304 } else { | 304 } else { |
305 NOTREACHED() << "lockf() failed." | 305 NOTREACHED() << "lockf() failed." |
306 << " function:" << function | 306 << " function:" << function |
307 << " fd:" << mapped_file_ | 307 << " fd:" << mapped_file_ |
308 << " errno:" << errno | 308 << " errno:" << errno |
309 << " msg:" << safe_strerror(errno); | 309 << " msg:" << safe_strerror(errno); |
310 } | 310 } |
311 } | 311 } |
312 } | 312 } |
313 | 313 |
314 void SharedMemory::Lock() { | 314 void SharedMemory::Lock() { |
315 LockOrUnlockCommon(F_LOCK); | 315 LockOrUnlockCommon(F_LOCK); |
316 } | 316 } |
317 | 317 |
318 void SharedMemory::Unlock() { | 318 void SharedMemory::Unlock() { |
319 LockOrUnlockCommon(F_ULOCK); | 319 LockOrUnlockCommon(F_ULOCK); |
320 } | 320 } |
321 | 321 |
322 SharedMemoryHandle SharedMemory::handle() const { | 322 SharedMemoryHandle SharedMemory::handle() const { |
323 return FileDescriptor(mapped_file_, false); | 323 return FileDescriptor(mapped_file_, false); |
324 } | 324 } |
325 | 325 |
326 } // namespace base | 326 } // namespace base |
OLD | NEW |