OLD | NEW |
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 Loading... |
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 Loading... |
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 |
OLD | NEW |