From dbf12de77ed89c74a5f6c135626c5f1c7271c19d Mon Sep 17 00:00:00 2001 From: sage Date: Tue, 28 Jun 2005 19:48:36 +0000 Subject: [PATCH] *** empty log message *** git-svn-id: https://ceph.svn.sf.net/svnroot/ceph@358 29311d96-e01e-0410-9327-a35deaab8ce9 --- ceph/config.cc | 4 ++++ ceph/include/buffer.h | 34 ++++++++++++++++++++++++++++++---- ceph/messages/MClientRequest.h | 2 +- 3 files changed, 35 insertions(+), 5 deletions(-) diff --git a/ceph/config.cc b/ceph/config.cc index dbb1430ec7642..b003c3fedf1ed 100644 --- a/ceph/config.cc +++ b/ceph/config.cc @@ -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 using namespace std; + + void parse_config_options(int argc, char **argv, int& nargc, char**&nargv) { diff --git a/ceph/include/buffer.h b/ceph/include/buffer.h index ce0382fcae84b..583b5a9820e3a 100644 --- a/ceph/include/buffer.h +++ b/ceph/include/buffer.h @@ -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(); + } } diff --git a/ceph/messages/MClientRequest.h b/ceph/messages/MClientRequest.h index 80036b9393e74..e4d084be5814f 100644 --- a/ceph/messages/MClientRequest.h +++ b/ceph/messages/MClientRequest.h @@ -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); -- 2.39.5