[everything] Fix circular shared pointer references.

We had a cycle from transaction_manager <-> space_map, and also from
the ref_counters back up to the tm.

This prevented objects being destroyed when various programs exited.

From now on we'll try and only use a shared ptr if ownership is
implied.  Otherwise a reference will be used (eg, for up pointers).
This commit is contained in:
Joe Thornber
2014-08-26 11:14:49 +01:00
parent 930cc9d412
commit a7c96c0e1e
31 changed files with 391 additions and 406 deletions

View File

@@ -31,21 +31,28 @@ using namespace testing;
namespace {
block_address const NR_BLOCKS = 102400;
transaction_manager::ptr
create_tm() {
block_manager<>::ptr bm(new block_manager<>("./test.data", NR_BLOCKS, 4, block_manager<>::READ_WRITE));
space_map::ptr sm(new core_map(NR_BLOCKS));
transaction_manager::ptr tm(new transaction_manager(bm, sm));
return tm;
}
class BtreeTests : public Test {
public:
BtreeTests()
: bm_(new block_manager<>("./test.data", NR_BLOCKS, 4, block_manager<>::READ_WRITE)),
sm_(new core_map(NR_BLOCKS)),
tm_(bm_, sm_) {
}
btree<1, uint64_traits>::ptr
create_btree() {
uint64_traits::ref_counter rc;
btree<1, uint64_traits>::ptr
create_btree() {
uint64_traits::ref_counter rc;
return btree<1, uint64_traits>::ptr(
new btree<1, uint64_traits>(tm_, rc));
}
private:
block_manager<>::ptr bm_;
space_map::ptr sm_;
transaction_manager tm_;
};
return btree<1, uint64_traits>::ptr(
new btree<1, uint64_traits>(create_tm(), rc));
}
// Checks that a btree is well formed.
//
@@ -99,7 +106,7 @@ namespace {
//----------------------------------------------------------------
TEST(BtreeTests, empty_btree_contains_nothing)
TEST_F(BtreeTests, empty_btree_contains_nothing)
{
btree<1, uint64_traits>::ptr tree = create_btree();
check_constraints(tree);
@@ -110,7 +117,7 @@ TEST(BtreeTests, empty_btree_contains_nothing)
}
}
TEST(BtreeTests, insert_works)
TEST_F(BtreeTests, insert_works)
{
unsigned const COUNT = 100000;
@@ -129,7 +136,7 @@ TEST(BtreeTests, insert_works)
check_constraints(tree);
}
TEST(BtreeTests, insert_does_not_insert_imaginary_values)
TEST_F(BtreeTests, insert_does_not_insert_imaginary_values)
{
btree<1, uint64_traits>::ptr tree = create_btree();
uint64_t key[1] = {0};
@@ -156,7 +163,7 @@ TEST(BtreeTests, insert_does_not_insert_imaginary_values)
check_constraints(tree);
}
TEST(BtreeTests, clone)
TEST_F(BtreeTests, clone)
{
typedef btree<1, uint64_traits> tree64;