OLD | NEW |
---|---|
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 #ifndef BASE_SHARED_MEMORY_H_ | 5 #ifndef BASE_SHARED_MEMORY_H_ |
6 #define BASE_SHARED_MEMORY_H_ | 6 #define BASE_SHARED_MEMORY_H_ |
7 | 7 |
8 #include "build/build_config.h" | 8 #include "build/build_config.h" |
9 | 9 |
10 #include <string> | 10 #include <string> |
(...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
137 | 137 |
138 // Opens a shared memory segment based on a name. | 138 // Opens a shared memory segment based on a name. |
139 // If read_only is true, opens for read-only access. | 139 // If read_only is true, opens for read-only access. |
140 // Returns true on success, false on failure. | 140 // Returns true on success, false on failure. |
141 bool Open(const std::string& name, bool read_only); | 141 bool Open(const std::string& name, bool read_only); |
142 | 142 |
143 // Maps the shared memory into the caller's address space. | 143 // Maps the shared memory into the caller's address space. |
144 // Returns true on success, false otherwise. The memory address | 144 // Returns true on success, false otherwise. The memory address |
145 // is accessed via the memory() accessor. The mapped address is guaranteed to | 145 // is accessed via the memory() accessor. The mapped address is guaranteed to |
146 // have an alignment of at least MAP_MINIMUM_ALIGNMENT. | 146 // have an alignment of at least MAP_MINIMUM_ALIGNMENT. |
147 bool Map(size_t bytes); | 147 bool Map(size_t bytes) { |
148 return MapFrom(0, bytes); | |
149 } | |
150 | |
151 // Same as above, but with |offset| to specify from begining of the shared | |
152 // memory block to map. | |
153 // |offset| must be alignent to value of |SysInfo::VMAllocationGranularity()|. | |
154 bool MapFrom(off_t offset, size_t bytes); | |
Mark Mentovai
2013/01/15 21:51:42
Isn’t this more MapAt than MapFrom?
Vitaly Buka (NO REVIEWS)
2013/01/15 22:13:05
Done.
Ideally I'd included offest to Map() interf
| |
148 enum { MAP_MINIMUM_ALIGNMENT = 32 }; | 155 enum { MAP_MINIMUM_ALIGNMENT = 32 }; |
149 | 156 |
150 // Unmaps the shared memory from the caller's address space. | 157 // Unmaps the shared memory from the caller's address space. |
151 // Returns true if successful; returns false on error or if the | 158 // Returns true if successful; returns false on error or if the |
152 // memory is not mapped. | 159 // memory is not mapped. |
153 bool Unmap(); | 160 bool Unmap(); |
154 | 161 |
155 // Get the size of the shared memory backing file. | 162 // Get the size of the shared memory backing file. |
156 // Note: This size is only available to the creator of the | 163 // Note: This size is only available to the creator of the |
157 // shared memory, and not to those that opened shared memory | 164 // shared memory, and not to those that opened shared memory |
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
266 } | 273 } |
267 | 274 |
268 private: | 275 private: |
269 SharedMemory* shared_memory_; | 276 SharedMemory* shared_memory_; |
270 DISALLOW_COPY_AND_ASSIGN(SharedMemoryAutoLock); | 277 DISALLOW_COPY_AND_ASSIGN(SharedMemoryAutoLock); |
271 }; | 278 }; |
272 | 279 |
273 } // namespace base | 280 } // namespace base |
274 | 281 |
275 #endif // BASE_SHARED_MEMORY_H_ | 282 #endif // BASE_SHARED_MEMORY_H_ |
OLD | NEW |