Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(846)

Unified Diff: mojo/system/raw_shared_buffer.h

Issue 219023010: Mojo: RawSharedBuffer::Mapping -> RawSharedBufferMapping. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: win Created 6 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « mojo/system/dispatcher_unittest.cc ('k') | mojo/system/raw_shared_buffer.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: mojo/system/raw_shared_buffer.h
diff --git a/mojo/system/raw_shared_buffer.h b/mojo/system/raw_shared_buffer.h
index c7a287cbd4a9fdccec152aa58c0df075e1501b2f..863584f2ad5346953ce08f56e4d34f4af8f72a33 100644
--- a/mojo/system/raw_shared_buffer.h
+++ b/mojo/system/raw_shared_buffer.h
@@ -17,12 +17,14 @@
namespace mojo {
namespace system {
+class RawSharedBufferMapping;
+
// |RawSharedBuffer| is a thread-safe, ref-counted wrapper around OS-specific
// shared memory. It has the following features:
// - A |RawSharedBuffer| simply represents a piece of shared memory that *may*
// be mapped and *may* be shared to another process.
// - A single |RawSharedBuffer| may be mapped multiple times. The lifetime of
-// the mapping (owned by |RawSharedBuffer::Mapping|) is separate from the
+// the mapping (owned by |RawSharedBufferMapping|) is separate from the
// lifetime of the |RawSharedBuffer|.
// - Sizes/offsets (of the shared memory and mappings) are arbitrary, and not
// restricted by page size. However, more memory may actually be mapped than
@@ -35,34 +37,6 @@ namespace system {
class MOJO_SYSTEM_IMPL_EXPORT RawSharedBuffer
: public base::RefCountedThreadSafe<RawSharedBuffer> {
public:
- // A mapping of a |RawSharedBuffer| (compararable to a "file view" in
- // Windows); see above. Created by |RawSharedBuffer::Map()|. Automatically
- // unmaps memory on destruction.
- //
- // Mappings are NOT thread-safe.
- class MOJO_SYSTEM_IMPL_EXPORT Mapping {
- public:
- ~Mapping() { Unmap(); }
-
- void* base() const { return base_; }
- size_t length() const { return length_; }
-
- private:
- friend class RawSharedBuffer;
-
- Mapping(void* base, size_t length, void* real_base, size_t real_length)
- : base_(base), length_(length),
- real_base_(real_base), real_length_(real_length) {}
- void Unmap();
-
- void* const base_;
- const size_t length_;
-
- void* const real_base_;
- const size_t real_length_;
-
- DISALLOW_COPY_AND_ASSIGN(Mapping);
- };
// Creates a shared buffer of size |num_bytes| bytes (initially zero-filled).
// |num_bytes| must be nonzero. Returns null on failure.
@@ -71,14 +45,14 @@ class MOJO_SYSTEM_IMPL_EXPORT RawSharedBuffer
// Maps (some) of the shared buffer into memory; [|offset|, |offset + length|]
// must be contained in [0, |num_bytes|], and |length| must be at least 1.
// Returns null on failure.
- scoped_ptr<Mapping> Map(size_t offset, size_t length);
+ scoped_ptr<RawSharedBufferMapping> Map(size_t offset, size_t length);
// Checks if |offset| and |length| are valid arguments.
bool IsValidMap(size_t offset, size_t length);
// Like |Map()|, but doesn't check its arguments (which should have been
// preflighted using |IsValidMap()|).
- scoped_ptr<Mapping> MapNoCheck(size_t offset, size_t length);
+ scoped_ptr<RawSharedBufferMapping> MapNoCheck(size_t offset, size_t length);
size_t num_bytes() const { return num_bytes_; }
@@ -94,7 +68,8 @@ class MOJO_SYSTEM_IMPL_EXPORT RawSharedBuffer
// The platform-dependent part of |Map()|; doesn't check arguments. Called
// under |lock_|.
- scoped_ptr<Mapping> MapImplNoLock(size_t offset, size_t length);
+ scoped_ptr<RawSharedBufferMapping> MapImplNoLock(size_t offset,
+ size_t length);
const size_t num_bytes_;
@@ -104,6 +79,41 @@ class MOJO_SYSTEM_IMPL_EXPORT RawSharedBuffer
DISALLOW_COPY_AND_ASSIGN(RawSharedBuffer);
};
+// A mapping of a |RawSharedBuffer| (compararable to a "file view" in Windows);
+// see above. Created by |RawSharedBuffer::Map()|. Automatically unmaps memory
+// on destruction.
+//
+// Mappings are NOT thread-safe.
+//
+// Note: This is an entirely separate class (instead of
+// |RawSharedBuffer::Mapping|) so that it can be forward-declared.
+class MOJO_SYSTEM_IMPL_EXPORT RawSharedBufferMapping {
+ public:
+ ~RawSharedBufferMapping() { Unmap(); }
+
+ void* base() const { return base_; }
+ size_t length() const { return length_; }
+
+ private:
+ friend class RawSharedBuffer;
+
+ RawSharedBufferMapping(void* base,
+ size_t length,
+ void* real_base,
+ size_t real_length)
+ : base_(base), length_(length),
+ real_base_(real_base), real_length_(real_length) {}
+ void Unmap();
+
+ void* const base_;
+ const size_t length_;
+
+ void* const real_base_;
+ const size_t real_length_;
+
+ DISALLOW_COPY_AND_ASSIGN(RawSharedBufferMapping);
+};
+
} // namespace system
} // namespace mojo
« no previous file with comments | « mojo/system/dispatcher_unittest.cc ('k') | mojo/system/raw_shared_buffer.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698