]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
buffer: abstract raw data related methods
authorJosh Durgin <josh.durgin@inktank.com>
Wed, 16 Oct 2013 23:23:36 +0000 (16:23 -0700)
committerJosh Durgin <josh.durgin@inktank.com>
Sat, 23 Nov 2013 00:13:36 +0000 (16:13 -0800)
Create a virtual function that returns the raw data instead of
accessing it directly, so raw buffers backed by pipes can be used as
buffer::ptrs. Make raw::is_page_aligned() virtual so it will not need
to look at the raw data for a pipe-based buffer.

Signed-off-by: Josh Durgin <josh.durgin@inktank.com>
src/common/buffer.cc

index 493070557159e1dbc9d37d2abd16c407911f20f9..9dd98310d97ea0781ce324832b88b7143eea19e1 100644 (file)
@@ -89,6 +89,9 @@ static uint32_t simple_spinlock_t buffer_debug_lock = SIMPLE_SPINLOCK_INITIALIZE
     raw(const raw &other);
     const raw& operator=(const raw &other);
 
+    virtual char *get_data() {
+      return data;
+    }
     virtual raw* clone_empty() = 0;
     raw *clone() {
       raw *c = clone_empty();
@@ -100,7 +103,7 @@ static uint32_t simple_spinlock_t buffer_debug_lock = SIMPLE_SPINLOCK_INITIALIZE
       return len;
     }
 
-    bool is_page_aligned() {
+    virtual bool is_page_aligned() {
       return ((long)data & ~CEPH_PAGE_MASK) == 0;
     }
     bool is_n_page_sized() {
@@ -375,8 +378,14 @@ static uint32_t simple_spinlock_t buffer_debug_lock = SIMPLE_SPINLOCK_INITIALIZE
 
   bool buffer::ptr::at_buffer_tail() const { return _off + _len == _raw->len; }
 
-  const char *buffer::ptr::c_str() const { assert(_raw); return _raw->data + _off; }
-  char *buffer::ptr::c_str() { assert(_raw); return _raw->data + _off; }
+  const char *buffer::ptr::c_str() const {
+    assert(_raw);
+    return _raw->get_data() + _off;
+  }
+  char *buffer::ptr::c_str() {
+    assert(_raw);
+    return _raw->get_data() + _off;
+  }
 
   unsigned buffer::ptr::unused_tail_length() const
   {
@@ -389,13 +398,13 @@ static uint32_t simple_spinlock_t buffer_debug_lock = SIMPLE_SPINLOCK_INITIALIZE
   {
     assert(_raw);
     assert(n < _len);
-    return _raw->data[_off + n];
+    return _raw->get_data()[_off + n];
   }
   char& buffer::ptr::operator[](unsigned n)
   {
     assert(_raw);
     assert(n < _len);
-    return _raw->data[_off + n];
+    return _raw->get_data()[_off + n];
   }
 
   const char *buffer::ptr::raw_c_str() const { assert(_raw); return _raw->data; }