From: sage Date: Wed, 29 Jun 2005 06:02:27 +0000 (+0000) Subject: *** empty log message *** X-Git-Tag: v0.1~2019 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=07fc14bb4913767fc7c0444ab12b6c232039fa2b;p=ceph.git *** empty log message *** git-svn-id: https://ceph.svn.sf.net/svnroot/ceph@362 29311d96-e01e-0410-9327-a35deaab8ce9 --- diff --git a/ceph/client/Buffercache.h b/ceph/client/Buffercache.h index 5988adf28b4..5490b76dde7 100644 --- a/ceph/client/Buffercache.h +++ b/ceph/client/Buffercache.h @@ -16,6 +16,20 @@ class Buffercache; class Bufferhead : public LRUObject { + int ref; + + int get() { + assert(ref >= 0); + if (ref == 0) lru_pin(); + ref++; + } + int put() { + assert(ref > 0); + ref--; + if (ref == 0) lru_unpin(); + } + + public: // FIXME: make more private and write some accessors off_t offset; size_t len; @@ -27,11 +41,11 @@ class Bufferhead : public LRUObject { // write_waiters: threads waiting for writes into the buffer list read_waiters, write_waiters; Buffercache *bc; - ref = 0; // cons/destructors - Bufferhead(inodeno_t ino, off_t off, size_t len, Buffercache *bc, int state=BUFHD_STATE_CLEAN) { - this->ino = ino; + Bufferhead(inodeno_t ino, off_t off, size_t len, Buffercache *bc, int state=BUFHD_STATE_CLEAN) + : ref(0) { + this->ino = ino; this->offset = off; this->len = len; this->state = state; @@ -41,39 +55,29 @@ class Bufferhead : public LRUObject { } ~Bufferhead() { - list bl = bh->bl.buffers(); - for (list::iterator it == bl.begin(); - it != bl.end(); - it++) { - delete *it; - } } //Bufferhead(inodeno_t ino, off_t off, size_t len, int state); // ~Bufferhead(); FIXME: need to mesh with allocator scheme - void get() { - ref++; - assert(ref > 0); - } - - void put() { - assert (ref > 0); - ref--; - if (ref == 0) { - assert(!lru_pinned); - delete this; - } - } - void add_read_waiter(Cond *cond) { - read_waiters->push_back(cond); - lru_pin(); - } - - void add_write_waiter(Cond *cond) { - write_waiters->push_back(cond); - lru_pin(); + /** wait_for_(read|write) + * put Cond on local stack, block until woken up. + * _caller_ pins to avoid any race weirdness + */ + void wait_for_read(Mutex &lock) { + Cond cond; + get(); + read_waiters.push_back(&cond); + cond.Wait(lock); + put(); + } + void wait_for_write(Mutex &lock) { + Cond cond; + get(); + write_waiters.push_back(&cond); + cond.Wait(lock); + put(); } void wakeup_read_waiters() { @@ -83,9 +87,7 @@ class Bufferhead : public LRUObject { (*it)->Signal(); } read_waiters.clear(); - if (write_waiters.empty()) lru_unpin(); } - void wakeup_write_waiters() { for (list::iterator it = write_waiters.begin(); it != write_waiters.end(); @@ -93,7 +95,6 @@ class Bufferhead : public LRUObject { (*it)->Signal(); } write_waiters.clear(); - if (read_waiters.empty()) lru_unpin(); } void miss_start() { @@ -108,7 +109,7 @@ class Bufferhead : public LRUObject { wakeup_write_waiters(); } - void dirty() { + void mark_dirty() { if (state == BUFHD_STATE_CLEAN) { state = BUFHD_STATE_DIRTY; bc->dirty_size += bh->len; @@ -151,6 +152,7 @@ class Bufferhead : public LRUObject { } }; + class Filecache { public: map buffer_map;