]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
common/buffer: changed buffer from class to namespace
authorMichal Jarzabek <stiopa@gmail.com>
Sun, 22 Nov 2015 12:12:47 +0000 (12:12 +0000)
committerMichal Jarzabek <stiopa@gmail.com>
Mon, 30 Nov 2015 19:38:44 +0000 (19:38 +0000)
Since the buffer only contained static functions it doesn't make sense
for it to be a class. Changing it to a namespace will allow
bufferlist, bufferptr and bufferhash to be forward declared.
This wasn't possible when they were nested classes.

Function declarations for
inc_total_alloc and
dec_total_alloc
were removed from the header file and changed to static, to simulate
the private access specifier, which they were under.

Moved the operators inside the buffer namespace to take advantage of
the Argument Dependent Lookup.

Moved typedefs to  buffer_fwd header file which we can include when
only the forward declarations are needed.

Since the buffer is not a class anymore all the instances of
using ceph::buffer
were removed.

Signed-off-by: Michal Jarzabek <stiopa@gmail.com>
src/common/buffer.cc
src/include/Makefile.am
src/include/buffer.h
src/include/buffer_fwd.h [new file with mode: 0644]
src/test/librados/cls.cc
src/test/librados/cmd.cc
src/test/librados/misc.cc
src/test/librados/tier.cc
src/test/multi_stress_watch.cc
src/test/test_stress_watch.cc

index 9e0b12329deaaaffc70dbf207cb04f00b170b7df..10e01a00457d6330124b8ba78f825eb69482c7cd 100644 (file)
@@ -52,20 +52,26 @@ static simple_spinlock_t buffer_debug_lock = SIMPLE_SPINLOCK_INITIALIZER;
   static atomic64_t buffer_history_alloc_num;
   const bool buffer_track_alloc = get_env_bool("CEPH_BUFFER_TRACK");
 
-  void buffer::inc_total_alloc(unsigned len) {
+  namespace {
+  void inc_total_alloc(unsigned len) {
     if (buffer_track_alloc)
       buffer_total_alloc.add(len);
   }
-  void buffer::dec_total_alloc(unsigned len) {
+
+  void dec_total_alloc(unsigned len) {
     if (buffer_track_alloc)
       buffer_total_alloc.sub(len);
   }
-  void buffer::inc_history_alloc(uint64_t len) {
+
+  void inc_history_alloc(uint64_t len) {
     if (buffer_track_alloc) {
       buffer_history_alloc_bytes.add(len);
       buffer_history_alloc_num.inc();
     }
   }
+  }
+
+
   int buffer::get_total_alloc() {
     return buffer_total_alloc.read();
   }
@@ -2118,11 +2124,11 @@ void buffer::list::hexdump(std::ostream &out) const
   out.flags(original_flags);
 }
 
-std::ostream& operator<<(std::ostream& out, const buffer::raw &r) {
+std::ostream& buffer::operator<<(std::ostream& out, const buffer::raw &r) {
   return out << "buffer::raw(" << (void*)r.data << " len " << r.len << " nref " << r.nref.read() << ")";
 }
 
-std::ostream& operator<<(std::ostream& out, const buffer::ptr& bp) {
+std::ostream& buffer::operator<<(std::ostream& out, const buffer::ptr& bp) {
   if (bp.have_raw())
     out << "buffer::ptr(" << bp.offset() << "~" << bp.length()
        << " " << (void*)bp.c_str()
@@ -2134,7 +2140,7 @@ std::ostream& operator<<(std::ostream& out, const buffer::ptr& bp) {
   return out;
 }
 
-std::ostream& operator<<(std::ostream& out, const buffer::list& bl) {
+std::ostream& buffer::operator<<(std::ostream& out, const buffer::list& bl) {
   out << "buffer::list(len=" << bl.length() << "," << std::endl;
 
   std::list<buffer::ptr>::const_iterator it = bl.buffers().begin();
@@ -2147,9 +2153,8 @@ std::ostream& operator<<(std::ostream& out, const buffer::list& bl) {
   return out;
 }
 
-std::ostream& operator<<(std::ostream& out, const buffer::error& e)
+std::ostream& buffer::operator<<(std::ostream& out, const buffer::error& e)
 {
   return out << e.what();
 }
-
 }
index a364b295d6c25e7dcd77e69696ab776e7c44f60a..ffbdc35b3ba731ab2b94b9c4ae96aa15338927a5 100644 (file)
@@ -9,6 +9,7 @@ rados_include_DATA = \
        $(srcdir)/include/rados/rados_types.hpp \
        $(srcdir)/include/rados/librados.hpp \
        $(srcdir)/include/buffer.h \
+       $(srcdir)/include/buffer_fwd.h \
        $(srcdir)/include/page.h \
        $(srcdir)/include/crc32c.h \
        $(srcdir)/include/memory.h
@@ -52,6 +53,7 @@ noinst_HEADERS += \
        include/bitmapper.h \
        include/blobhash.h \
        include/buffer.h \
+       include/buffer_fwd.h \
        include/byteorder.h \
        include/cephfs/libcephfs.h \
        include/ceph_features.h \
index 2478d30b01ba16c98e9f05dc9a805b6ddc2398ee..2f01260c151cbac63900011e106491c4d4e4c051 100644 (file)
@@ -47,6 +47,7 @@
 
 #include "page.h"
 #include "crc32c.h"
+#include "include/buffer_fwd.h"
 
 #ifdef __CEPH__
 # include "include/assert.h"
@@ -69,12 +70,11 @@ namespace ceph {
 
 const static int CEPH_BUFFER_APPEND_SIZE(4096);
 
-class CEPH_BUFFER_API buffer {
+namespace buffer CEPH_BUFFER_API {
   /*
    * exceptions
    */
 
-public:
   struct error : public std::exception{
     const char *what() const throw ();
   };
@@ -99,35 +99,28 @@ public:
 
 
   /// total bytes allocated
-  static int get_total_alloc();
+  int get_total_alloc();
 
   /// history total bytes allocated
-  static uint64_t get_history_alloc_bytes();
+  uint64_t get_history_alloc_bytes();
 
   /// total num allocated
-  static uint64_t get_history_alloc_num();
+  uint64_t get_history_alloc_num();
 
   /// enable/disable alloc tracking
-  static void track_alloc(bool b);
+  void track_alloc(bool b);
 
   /// count of cached crc hits (matching input)
-  static int get_cached_crc();
+  int get_cached_crc();
   /// count of cached crc hits (mismatching input, required adjustment)
-  static int get_cached_crc_adjusted();
+  int get_cached_crc_adjusted();
   /// enable/disable tracking of cached crcs
-  static void track_cached_crc(bool b);
+  void track_cached_crc(bool b);
 
   /// count of calls to buffer::ptr::c_str()
-  static int get_c_str_accesses();
+  int get_c_str_accesses();
   /// enable/disable tracking of buffer::ptr::c_str() calls
-  static void track_c_str(bool b);
-
-private:
-  /* hack for memory utilization debugging. */
-  static void inc_total_alloc(unsigned len);
-  static void inc_history_alloc(uint64_t len);
-  static void dec_total_alloc(unsigned len);
+  void track_c_str(bool b);
 
   /*
    * an abstract raw buffer.  with a reference count.
@@ -142,25 +135,23 @@ private:
   class raw_pipe;
   class raw_unshareable; // diagnostic, unshareable char buffer
 
-  friend std::ostream& operator<<(std::ostream& out, const raw &r);
 
-public:
   class xio_mempool;
   class xio_msg_buffer;
 
   /*
    * named constructors 
    */
-  static raw* copy(const char *c, unsigned len);
-  static raw* create(unsigned len);
-  static raw* claim_char(unsigned len, char *buf);
-  static raw* create_malloc(unsigned len);
-  static raw* claim_malloc(unsigned len, char *buf);
-  static raw* create_static(unsigned len, char *buf);
-  static raw* create_aligned(unsigned len, unsigned align);
-  static raw* create_page_aligned(unsigned len);
-  static raw* create_zero_copy(unsigned len, int fd, int64_t *offset);
-  static raw* create_unshareable(unsigned len);
+  raw* copy(const char *c, unsigned len);
+  raw* create(unsigned len);
+  raw* claim_char(unsigned len, char *buf);
+  raw* create_malloc(unsigned len);
+  raw* claim_malloc(unsigned len, char *buf);
+  raw* create_static(unsigned len, char *buf);
+  raw* create_aligned(unsigned len, unsigned align);
+  raw* create_page_aligned(unsigned len);
+  raw* create_zero_copy(unsigned len, int fd, int64_t *offset);
+  raw* create_unshareable(unsigned len);
 
 #if defined(HAVE_XIO)
   static raw* create_msg(unsigned len, char *buf, XioDispatchHook *m_hook);
@@ -254,7 +245,6 @@ public:
 
   };
 
-  friend std::ostream& operator<<(std::ostream& out, const buffer::ptr& bp);
 
   /*
    * list - the useful bit!
@@ -562,16 +552,6 @@ public:
       return crc;
     }
   };
-};
-
-#if defined(HAVE_XIO)
-xio_reg_mem* get_xio_mp(const buffer::ptr& bp);
-#endif
-
-typedef buffer::ptr bufferptr;
-typedef buffer::list bufferlist;
-typedef buffer::hash bufferhash;
-
 
 inline bool operator>(bufferlist& l, bufferlist& r) {
   for (unsigned p = 0; ; p++) {
@@ -610,6 +590,7 @@ inline bool operator<=(bufferlist& l, bufferlist& r) {
 
 std::ostream& operator<<(std::ostream& out, const buffer::ptr& bp);
 
+std::ostream& operator<<(std::ostream& out, const raw &r);
 
 std::ostream& operator<<(std::ostream& out, const buffer::list& bl);
 
@@ -621,4 +602,10 @@ inline bufferhash& operator<<(bufferhash& l, bufferlist &r) {
 }
 }
 
+#if defined(HAVE_XIO)
+xio_reg_mem* get_xio_mp(const buffer::ptr& bp);
+#endif
+
+}
+
 #endif
diff --git a/src/include/buffer_fwd.h b/src/include/buffer_fwd.h
new file mode 100644 (file)
index 0000000..1646eff
--- /dev/null
@@ -0,0 +1,17 @@
+#ifndef BUFFER_FWD_H
+#define BUFFER_FWD_H
+
+namespace ceph {
+  namespace buffer {
+    class ptr;
+    class list;
+    class hash;
+  }
+
+  using bufferptr = buffer::ptr;
+  using bufferlist = buffer::list;
+  using bufferhash = buffer::hash;
+}
+
+#endif
+
index 1f61664b48782aeb999497f506f821473b1dfc54..10744b2b9b899f6a567695f39ef5a3dc04a5bc4f 100644 (file)
@@ -9,7 +9,6 @@
 #include <string>
 
 using namespace librados;
-using ceph::buffer;
 using std::map;
 using std::ostringstream;
 using std::string;
index 4f327a0e84b2b98c681217e2e0e24c3c3efd206d..d5e9d71fb6a5a9acb7765be1a00512837dcb069b 100644 (file)
@@ -18,7 +18,6 @@
 #include <string>
 
 using namespace librados;
-using ceph::buffer;
 using std::map;
 using std::ostringstream;
 using std::string;
index 4adaa6bf163f80bce8f62f012db4c44f25c9dc8c..0fb67e0d509b381ef9f38d51444873a379871461 100644 (file)
@@ -21,7 +21,6 @@
 #include <string>
 
 using namespace librados;
-using ceph::buffer;
 using std::map;
 using std::ostringstream;
 using std::string;
index 12ccfc29a0177640ba47f0af1acfb01013619558..6517f82b839f537db0b813e65a4a5d831f530c08 100644 (file)
@@ -26,7 +26,6 @@
 #include <string>
 
 using namespace librados;
-using ceph::buffer;
 using std::map;
 using std::ostringstream;
 using std::string;
index 25f735558f5c3721969bf011c9b0092aa9c4e3cf..4dc5489d51d746b51e333c2b8186d74edb45eca4 100644 (file)
@@ -13,7 +13,6 @@
 #include <unistd.h>
 
 using namespace librados;
-using ceph::buffer;
 using std::map;
 using std::ostringstream;
 using std::string;
index 9e66f0ecd66eeeb43971c75a00c209956c0382b1..6ddfee5047f9d0e8bbe44945d7f208fbcd3c51ba 100644 (file)
@@ -18,7 +18,6 @@
 
 
 using namespace librados;
-using ceph::buffer;
 using std::map;
 using std::ostringstream;
 using std::string;