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 "base/logging.h" | 7 #include "base/logging.h" |
8 #include "base/utf_string_conversions.h" | 8 #include "base/utf_string_conversions.h" |
9 | 9 |
10 namespace base { | 10 namespace base { |
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
73 bool SharedMemory::CreateAndMapAnonymous(uint32 size) { | 73 bool SharedMemory::CreateAndMapAnonymous(uint32 size) { |
74 return CreateAnonymous(size) && Map(size); | 74 return CreateAnonymous(size) && Map(size); |
75 } | 75 } |
76 | 76 |
77 bool SharedMemory::CreateAnonymous(uint32 size) { | 77 bool SharedMemory::CreateAnonymous(uint32 size) { |
78 return CreateNamed("", false, size); | 78 return CreateNamed("", false, size); |
79 } | 79 } |
80 | 80 |
81 bool SharedMemory::CreateNamed(const std::string& name, | 81 bool SharedMemory::CreateNamed(const std::string& name, |
82 bool open_existing, uint32 size) { | 82 bool open_existing, uint32 size) { |
83 DCHECK(mapped_file_ == NULL); | 83 DCHECK(!mapped_file_); |
84 if (size == 0) | 84 if (size == 0) |
85 return false; | 85 return false; |
86 | 86 |
87 // NaCl's memory allocator requires 0mod64K alignment and size for | 87 // NaCl's memory allocator requires 0mod64K alignment and size for |
88 // shared memory objects. To allow passing shared memory to NaCl, | 88 // shared memory objects. To allow passing shared memory to NaCl, |
89 // therefore we round the size actually created to the nearest 64K unit. | 89 // therefore we round the size actually created to the nearest 64K unit. |
90 // To avoid client impact, we continue to retain the size as the | 90 // To avoid client impact, we continue to retain the size as the |
91 // actual requested size. | 91 // actual requested size. |
92 uint32 rounded_size = (size + 0xffff) & ~0xffff; | 92 uint32 rounded_size = (size + 0xffff) & ~0xffff; |
93 name_ = ASCIIToWide(name); | 93 name_ = ASCIIToWide(name); |
(...skipping 18 matching lines...) Expand all Loading... |
112 | 112 |
113 return true; | 113 return true; |
114 } | 114 } |
115 | 115 |
116 bool SharedMemory::Delete(const std::string& name) { | 116 bool SharedMemory::Delete(const std::string& name) { |
117 // intentionally empty -- there is nothing for us to do on Windows. | 117 // intentionally empty -- there is nothing for us to do on Windows. |
118 return true; | 118 return true; |
119 } | 119 } |
120 | 120 |
121 bool SharedMemory::Open(const std::string& name, bool read_only) { | 121 bool SharedMemory::Open(const std::string& name, bool read_only) { |
122 DCHECK(mapped_file_ == NULL); | 122 DCHECK(!mapped_file_); |
123 | 123 |
124 name_ = ASCIIToWide(name); | 124 name_ = ASCIIToWide(name); |
125 read_only_ = read_only; | 125 read_only_ = read_only; |
126 mapped_file_ = OpenFileMapping( | 126 mapped_file_ = OpenFileMapping( |
127 read_only_ ? FILE_MAP_READ : FILE_MAP_ALL_ACCESS, false, | 127 read_only_ ? FILE_MAP_READ : FILE_MAP_ALL_ACCESS, false, |
128 name_.empty() ? NULL : name_.c_str()); | 128 name_.empty() ? NULL : name_.c_str()); |
129 if (mapped_file_ != NULL) { | 129 if (mapped_file_ != NULL) { |
130 // Note: size_ is not set in this case. | 130 // Note: size_ is not set in this case. |
131 return true; | 131 return true; |
132 } | 132 } |
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
219 void SharedMemory::Unlock() { | 219 void SharedMemory::Unlock() { |
220 DCHECK(lock_ != NULL); | 220 DCHECK(lock_ != NULL); |
221 ReleaseMutex(lock_); | 221 ReleaseMutex(lock_); |
222 } | 222 } |
223 | 223 |
224 SharedMemoryHandle SharedMemory::handle() const { | 224 SharedMemoryHandle SharedMemory::handle() const { |
225 return mapped_file_; | 225 return mapped_file_; |
226 } | 226 } |
227 | 227 |
228 } // namespace base | 228 } // namespace base |
OLD | NEW |