From: sage Date: Tue, 28 Jun 2005 16:41:31 +0000 (+0000) Subject: *** empty log message *** X-Git-Tag: v0.1~2025 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=ac9d0d44c18f9751387819c493ef4d2e6786f96f;p=ceph.git *** empty log message *** git-svn-id: https://ceph.svn.sf.net/svnroot/ceph@356 29311d96-e01e-0410-9327-a35deaab8ce9 --- diff --git a/ceph/client/Buffercache.h b/ceph/client/Buffercache.h index 62b4ae3c00433..fa30708a822ec 100644 --- a/ceph/client/Buffercache.h +++ b/ceph/client/Buffercache.h @@ -16,6 +16,17 @@ class Buffercache; class Bufferhead : public LRUObject { + // reference counter + int ref; + void get() { + if (ref == 0) lru_pin(); + ++ref; + } + void put() { + --ref; + if (ref == 0) lru_unpin(); + } + public: // FIXME: make more private and write some accessors off_t offset; size_t len; @@ -30,6 +41,7 @@ class Bufferhead : public LRUObject { // cons/destructors Bufferhead(inodeno_t ino, off_t off, size_t len, Buffercache *bc, int state=BUFHD_STATE_CLEAN) { + this->ref = 0; this->ino = ino; this->offset = off; this->len = len; @@ -40,28 +52,32 @@ class Bufferhead : public LRUObject { } ~Bufferhead() { - list bl = bh->bl.buffers(); - for (list::iterator it == bl.begin(); - it != bl.end(); - it++) { - delete *it; - } + // no need to delete bufferlist bufferptr's explicitly; ~list() does that (since it's list, not list) } //Bufferhead(inodeno_t ino, off_t off, size_t len, int state); // ~Bufferhead(); FIXME: need to mesh with allocator scheme - void add_read_waiter(Cond *cond) { - read_waiters->push_back(cond); - lru_pin(); + + // -- wait for read, write: these will block + // i think this will work okay? and reference coutning in the waiter makes sure the wakeup fn doesn't + // inadvertantly unpin the bufferhead before the waiters get to go + void wait_for_read(Mutex& lock) { + Cond cond; // on local stack + get(); + read_waiters.push_back(&cond); + cond.Wait(lock); + put(); } - - void add_write_waiter(Cond *cond) { - write_waiters->push_back(cond); - lru_pin(); + void wait_for_write(Mutex& lock) { + Cond cond; // on local stack + get(); + write_waiters.push_back(&cond); + cond.Wait(lock); + put(); } - + void wakeup_read_waiters() { for (list::iterator it = read_waiters.begin(); it != read_waiters.end(); @@ -69,7 +85,6 @@ class Bufferhead : public LRUObject { (*it)->Signal(); } read_waiters.clear(); - if (write_waiters.empty()) lru_unpin(); } void wakeup_write_waiters() { @@ -78,8 +93,6 @@ class Bufferhead : public LRUObject { it++) { (*it)->Signal(); } - write_waiters.clear(); - if (read_waiters.empty()) lru_unpin(); } void miss_start() {