From 77adb08c3f2c5c61db74549b87b3a51e0e074084 Mon Sep 17 00:00:00 2001 From: Ming-Hung Tsai Date: Sun, 31 May 2020 20:35:37 +0800 Subject: [PATCH] [thin_pool] Replace the member pointer by references --- thin-provisioning/thin_pool.cc | 20 ++++++++++---------- thin-provisioning/thin_pool.h | 4 ++-- 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/thin-provisioning/thin_pool.cc b/thin-provisioning/thin_pool.cc index ffb9936..1436b4b 100644 --- a/thin-provisioning/thin_pool.cc +++ b/thin-provisioning/thin_pool.cc @@ -31,7 +31,7 @@ using namespace thin_provisioning; //---------------------------------------------------------------- -thin::thin(thin_dev_t dev, thin_pool *pool) +thin::thin(thin_dev_t dev, thin_pool &pool) : dev_(dev), pool_(pool) { @@ -47,7 +47,7 @@ thin::maybe_address thin::lookup(block_address thin_block) { uint64_t key[2] = {dev_, thin_block}; - return pool_->md_->mappings_->lookup(key); + return pool_.md_->mappings_->lookup(key); } bool @@ -57,33 +57,33 @@ thin::insert(block_address thin_block, block_address data_block) mapping_tree_detail::block_time bt; bt.block_ = data_block; bt.time_ = 0; // FIXME: use current time. - return pool_->md_->mappings_->insert(key, bt); + return pool_.md_->mappings_->insert(key, bt); } void thin::remove(block_address thin_block) { uint64_t key[2] = {dev_, thin_block}; - pool_->md_->mappings_->remove(key); + pool_.md_->mappings_->remove(key); } void thin::set_snapshot_time(uint32_t time) { uint64_t key[1] = { dev_ }; - boost::optional mdetail = pool_->md_->details_->lookup(key); + boost::optional mdetail = pool_.md_->details_->lookup(key); if (!mdetail) throw runtime_error("no such device"); mdetail->snapshotted_time_ = time; - pool_->md_->details_->insert(key, *mdetail); + pool_.md_->details_->insert(key, *mdetail); } block_address thin::get_mapped_blocks() const { uint64_t key[1] = { dev_ }; - boost::optional mdetail = pool_->md_->details_->lookup(key); + boost::optional mdetail = pool_.md_->details_->lookup(key); if (!mdetail) throw runtime_error("no such device"); @@ -94,12 +94,12 @@ void thin::set_mapped_blocks(block_address count) { uint64_t key[1] = { dev_ }; - boost::optional mdetail = pool_->md_->details_->lookup(key); + boost::optional mdetail = pool_.md_->details_->lookup(key); if (!mdetail) throw runtime_error("no such device"); mdetail->mapped_blocks_ = count; - pool_->md_->details_->insert(key, *mdetail); + pool_.md_->details_->insert(key, *mdetail); } //-------------------------------- @@ -234,7 +234,7 @@ thin_pool::open_thin(thin_dev_t dev) if (!mdetails) throw runtime_error("no such device"); - thin *ptr = new thin(dev, this); + thin *ptr = new thin(dev, *this); thin::ptr r(ptr); return r; } diff --git a/thin-provisioning/thin_pool.h b/thin-provisioning/thin_pool.h index 7b95e12..abbb47b 100644 --- a/thin-provisioning/thin_pool.h +++ b/thin-provisioning/thin_pool.h @@ -48,10 +48,10 @@ namespace thin_provisioning { private: friend class thin_pool; - thin(thin_dev_t dev, thin_pool *pool); // FIXME: pass a reference rather than a ptr + thin(thin_dev_t dev, thin_pool &pool); thin_dev_t dev_; - thin_pool *pool_; + thin_pool &pool_; }; class thin_pool {