]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
*** empty log message ***
authorsage <sage@29311d96-e01e-0410-9327-a35deaab8ce9>
Tue, 28 Jun 2005 19:48:36 +0000 (19:48 +0000)
committersage <sage@29311d96-e01e-0410-9327-a35deaab8ce9>
Tue, 28 Jun 2005 19:48:36 +0000 (19:48 +0000)
git-svn-id: https://ceph.svn.sf.net/svnroot/ceph@358 29311d96-e01e-0410-9327-a35deaab8ce9

ceph/config.cc
ceph/include/buffer.h
ceph/messages/MClientRequest.h

index dbb1430ec7642515a4367cf945bd994f34214161..b003c3fedf1ed800d2c64dd1818c39139a30a357 100644 (file)
@@ -15,6 +15,8 @@
 
 // hack hack hack ugly FIXME
 long buffer_total_alloc = 0;
+Mutex bufferlock;
+
 
 
 OSDFileLayout g_OSD_FileLayout( 1<<20, 1, 1<<20 );   // stripe files over whole objects
@@ -122,6 +124,8 @@ md_config_t g_conf = {
 #include <iostream>
 using namespace std;
 
+
+
 void parse_config_options(int argc, char **argv,
                                                  int& nargc, char**&nargv)
 {
index ce0382fcae84bab4331a552a996241400207d7aa..583b5a9820e3ad2e4bd4c0244601ba92bda2243f 100644 (file)
@@ -20,9 +20,27 @@ using namespace std;
 #include "include/config.h"
 #define bdbout(x) if (x <= g_conf.debug_buffer) cout
 
+#include "common/Mutex.h"
 
+// HACK: in config.cc
+/*
+ * WARNING: bufferlock placements are tricky for efficiency.  note that only bufferptr and
+ * buffer ever use buffer._ref, and only bufferptr should call ~buffer().
+ *
+ * So, I only need to protect:
+ *  - buffer()'s modification of buffer_total_alloc
+ *  - ~bufferptr() check of buffer._ref, and ~buffer's mod of buffer_total_alloc
+ * 
+ * I don't protect
+ *  - buffer._get() .. increment is atomic on any sane architecture
+ *  - buffer._put() .. only called by ~bufferptr.
+ *  - ~buffer       .. only called by ~bufferptr   *** I HOPE!!  
+ */
+extern Mutex bufferlock;
 extern long buffer_total_alloc;
 
+
+
 /*
  * buffer  - the underlying buffer container.  with a reference count.
  * 
@@ -43,11 +61,11 @@ class buffer {
   int _ref;
   int _get() { 
        bdbout(1) << "buffer.get " << *this << " get " << _ref+1 << endl;
-       return ++_ref; 
+       return ++_ref;
   }
   int _put() { 
        bdbout(1) << "buffer.put " << *this << " put " << _ref-1 << endl;
-       return --_ref; 
+       return --_ref;
   }
   
   friend class bufferptr;
@@ -60,7 +78,9 @@ class buffer {
   buffer(int a) : _dataptr(0), _len(0), _alloc_len(a), _ref(0), _myptr(true) {
        bdbout(1) << "buffer.cons " << *this << endl;
        _dataptr = new char[a];
+       bufferlock.Lock();
        buffer_total_alloc += _alloc_len;
+       bufferlock.Unlock();
        bdbout(1) << "buffer.malloc " << (void*)_dataptr << endl;
   }
   ~buffer() {
@@ -88,7 +108,9 @@ class buffer {
        if (mode & BUFFER_MODE_COPY) {
          _dataptr = new char[_alloc_len];
          bdbout(1) << "buffer.malloc " << (void*)_dataptr << endl;
+         bufferlock.Lock();
          buffer_total_alloc += _alloc_len;
+         bufferlock.Unlock();
          memcpy(_dataptr, p, l);
          bdbout(1) << "buffer.copy " << *this << endl;
        } else {
@@ -186,8 +208,12 @@ class bufferptr {
   }
 
   ~bufferptr() {
-       if (_buffer && _buffer->_put() == 0) 
-         delete _buffer;
+       if (_buffer) {
+         bufferlock.Lock();
+         if (_buffer->_put() == 0) 
+               delete _buffer;
+         bufferlock.Unlock();
+       }
   }
 
 
index 80036b9393e74e32aeb3f1dd90456c5239ee3a18..e4d084be5814fc0c38c0bd5942b6e751c635bf23 100644 (file)
@@ -102,7 +102,7 @@ class MClientRequest : public Message {
   size_t get_sizearg() { return st.sizearg; }
 
   virtual void decode_payload() {
-       int off;
+       int off = 0;
        payload.copy(off, sizeof(st), (char*)&st);
        off += sizeof(st);
        path._decode(payload, off);