Index: base/shared_memory.h |
diff --git a/base/shared_memory.h b/base/shared_memory.h |
index c9dfd6eb05c2357f2bfded6c283dfb8b8638c213..a4575035a3f7b8ca2620f780c8b696427e88b5dc 100644 |
--- a/base/shared_memory.h |
+++ b/base/shared_memory.h |
@@ -38,6 +38,36 @@ typedef ino_t SharedMemoryId; |
// needed. |
#endif |
+// Options for creating a shared memory object. |
+struct SharedMemoryCreateOptions { |
+ SharedMemoryCreateOptions() : name(NULL), open_existing(false), |
+ size(0), executable(false) |
+ {} |
Mark Mentovai
2011/12/01 19:31:16
{} belongs on the preceding line, or { on the prec
|
+ |
+ explicit SharedMemoryCreateOptions(uint32 isize) : name(NULL), |
Mark Mentovai
2011/12/01 19:31:16
Why do we need this form of the constructor? Can’t
|
+ open_existing(false), |
+ size(isize), |
+ executable(false) |
+ {} |
+ |
+ // If NULL, the object is anonymous. This pointer is owned by the caller |
+ // and must live through the call to Create(). |
+ const std::string* name; |
+ |
+ // If true, and the shared memory already exists, Create() will open the |
+ // existing shared memory and ignore the size parameter. If false, |
+ // shared memory must not exist. This flag is meaningless unless name is |
+ // non-NULL. |
+ bool open_existing; |
+ |
+ // Size of the shared memory object to be created. |
+ // When opening an existing object, this has no effect. |
+ uint32 size; |
+ |
+ // If true, mappings might need to be made executable later. |
+ bool executable; |
+}; |
+ |
// Platform abstraction for shared memory. Provides a C++ wrapper |
// around the OS primitive for a memory mapped file. |
class BASE_EXPORT SharedMemory { |
@@ -74,13 +104,20 @@ class BASE_EXPORT SharedMemory { |
// Closes a shared memory handle. |
static void CloseHandle(const SharedMemoryHandle& handle); |
+ // Creates a shared memory object as described by the options struct. |
+ // Returns true on success and false on failure. |
+ bool Create(const SharedMemoryCreateOptions& options); |
+ |
// Creates and maps an anonymous shared memory segment of size size. |
// Returns true on success and false on failure. |
bool CreateAndMapAnonymous(uint32 size); |
// Creates an anonymous shared memory segment of size size. |
// Returns true on success and false on failure. |
- bool CreateAnonymous(uint32 size); |
+ bool CreateAnonymous(uint32 size) { |
+ SharedMemoryCreateOptions options(size); |
+ return Create(options); |
+ } |
// Creates or opens a shared memory segment based on a name. |
// If open_existing is true, and the shared memory already exists, |
@@ -88,7 +125,12 @@ class BASE_EXPORT SharedMemory { |
// If open_existing is false, shared memory must not exist. |
// size is the size of the block to be created. |
// Returns true on success, false on failure. |
- bool CreateNamed(const std::string& name, bool open_existing, uint32 size); |
+ bool CreateNamed(const std::string& name, bool open_existing, uint32 size) { |
+ SharedMemoryCreateOptions options(size); |
+ options.name = &name; |
+ options.open_existing = open_existing; |
+ return Create(options); |
+ } |
// Deletes resources associated with a shared memory segment based on name. |
// Not all platforms require this call. |