From 7ff4221b9502de483685e3412f72d5223aff32f5 Mon Sep 17 00:00:00 2001 From: baldas Date: Fri, 21 Nov 2014 18:10:51 -0800 Subject: [PATCH 1/7] Adding the Smart pointer implementation file. --- system/SmartPointer.hpp | 161 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 161 insertions(+) create mode 100644 system/SmartPointer.hpp diff --git a/system/SmartPointer.hpp b/system/SmartPointer.hpp new file mode 100644 index 000000000..0865069e3 --- /dev/null +++ b/system/SmartPointer.hpp @@ -0,0 +1,161 @@ +//////////////////////////////////////////////////////////////////////// +// This file is part of Grappa, a system for scaling irregular +// applications on commodity clusters. + +// Copyright (C) 2010-2014 University of Washington and Battelle +// Memorial Institute. University of Washington authorizes use of this +// Grappa software. + +// Grappa is free software: you can redistribute it and/or modify it +// under the terms of the Affero General Public License as published +// by Affero, Inc., either version 1 of the License, or (at your +// option) any later version. + +// Grappa is distributed in the hope that it will be useful, but +// WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// Affero General Public License for more details. + +// You should have received a copy of the Affero General Public +// License along with this program. If not, you may obtain one from +// http://www.affero.org/oagpl.html. +//////////////////////////////////////////////////////////////////////// + + +#ifndef _SMTPTR_HPP__ +#define _SMTPTR_HPP__ + +#include + +using namespace Grappa; + +#if 0 +# include +using namespace std; +# define DPRINT(m) cout << setw(14) << (this) << ": " << m << endl +# define DPRINT2(m,n) cout << setw(14) << (this) << ": " << m << n << endl +#else +# define DPRINT(m) +# define DPRINT2(m,n) +#endif + +/* + * Reference manager class. + * + * + */ +template +class RefManager +{ + T *ptr; /* pointer to the object */ + size_t refcnt; /* reference counter */ + +public: + + explicit RefManager(T *p = 0) : ptr(p), refcnt(1) + { + DPRINT("*** RefManager constructor ***"); + } + + ~RefManager() + { + DPRINT("*** RefManager destructor ***"); + } + + T& getRef() { return *ptr; } + T* getPtr() { return ptr; } + + void Increment() + { + refcnt++; + DPRINT2(" -> RefManager incremented: ", refcnt); + } + + size_t Decrement() + { + refcnt--; + DPRINT2(" -> RefManager decremented: ", refcnt); + if (refcnt == 0) { + DPRINT(" -> RefManager: Object deleted"); + delete ptr; + } + return refcnt; + } + +// size_t numRefs() const { return refcnt; } +}; + + +/* forward declaration for the clone function */ +template +T *clone(GlobalAddress obj); + + + + +// +// Smart Pointer class +// +// +template +class SmtPtr +{ + GlobalAddress< RefManager > refMan; /* Global address of the reference manager */ + +public: + explicit SmtPtr(T *ptr): refMan(make_global(new RefManager(ptr))) + { + DPRINT("*** SmtPtr constructor ***"); + } + + // copy constructor + SmtPtr(const SmtPtr &other): refMan(other.refMan) + { + DPRINT("*** SmtPtr copy constructor ***"); + + delegate::call(refMan, [](RefManager *ref) { ref->Increment(); }); + } + +// T& operator*() { return reference_->getRef(); } + + T* operator->() + { + // assert it is not called from remote node + return refMan->getPtr(); + } + + + SmtPtr clone() const + { + DPRINT(" -> SmtPtr clone"); + + T *local = ::clone(delegate::call(refMan, [](RefManager *ref) + { return make_global(ref->getPtr()); })); + + return SmtPtr(local); + } + + +// size_t getNumRefs() const +// { +// return delegate::call(refMan, [](RefManager *ref) { return ref->numRefs(); }); +// } + + + // destructor + ~SmtPtr() + { + DPRINT("*** SmtPtr destructor ***"); + + RefManager *ref = (RefManager *)refMan.pointer(); + delegate::call(refMan.core(), [ref] { if (!ref->Decrement()) delete ref; }); + } + +}; + + + + + + +#endif /* _SMTPTR_HPP_ */ From 1b36a8e542de4fbd1ffe8c52528370f35b532c5f Mon Sep 17 00:00:00 2001 From: baldas Date: Mon, 24 Nov 2014 10:23:04 -0800 Subject: [PATCH 2/7] removed dead code --- system/SmartPointer.hpp | 10 +--------- 1 file changed, 1 insertion(+), 9 deletions(-) diff --git a/system/SmartPointer.hpp b/system/SmartPointer.hpp index 0865069e3..9265589c3 100644 --- a/system/SmartPointer.hpp +++ b/system/SmartPointer.hpp @@ -120,7 +120,7 @@ class SmtPtr T* operator->() { - // assert it is not called from remote node + // TODO: assert it is not called from remote node return refMan->getPtr(); } @@ -136,12 +136,6 @@ class SmtPtr } -// size_t getNumRefs() const -// { -// return delegate::call(refMan, [](RefManager *ref) { return ref->numRefs(); }); -// } - - // destructor ~SmtPtr() { @@ -156,6 +150,4 @@ class SmtPtr - - #endif /* _SMTPTR_HPP_ */ From a0600c082346519405488c756e8e5251f763ab7c Mon Sep 17 00:00:00 2001 From: baldas Date: Mon, 24 Nov 2014 10:27:33 -0800 Subject: [PATCH 3/7] Added more meaningful comments. --- applications/demos/nqueens/nqueens.cpp | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/applications/demos/nqueens/nqueens.cpp b/applications/demos/nqueens/nqueens.cpp index 01f923f06..0890df253 100644 --- a/applications/demos/nqueens/nqueens.cpp +++ b/applications/demos/nqueens/nqueens.cpp @@ -116,14 +116,15 @@ class Board { /* * This is basically a brute force solution using recursion. * - * Given a board ('remoteBoard') we check if placing a queen in any of the - * rows of the column given by 'columnIndex' is safe. In such cases a new task - * is spawned recursively for the next column. + * Given a board ('remoteBoard') we add a queen at the row given by 'rowIndex' + * in the last column, and check whether it is safe to add a new queen in any + * of the rows of the next column. In such cases a new task is spawned + * recursively for the next column. */ -void nqSearch(GlobalAddress remoteBoard, int columnIndex) +void nqSearch(GlobalAddress remoteBoard, int rowIndex) { /* create a new copy of remoteBoard, adding a new column */ - Board *newBoard = new Board(remoteBoard, columnIndex); + Board *newBoard = new Board(remoteBoard, rowIndex); /* are we done yet? */ if (newBoard->Size() == nqBoardSize) From 6dabb9c1ee97778a6d1ea196e5161ef9c58ade26 Mon Sep 17 00:00:00 2001 From: baldas Date: Mon, 24 Nov 2014 10:32:44 -0800 Subject: [PATCH 4/7] Version of NQueens with SmartPointers support. --- applications/demos/nqueens/nqueens-smt.cpp | 209 +++++++++++++++++++++ 1 file changed, 209 insertions(+) create mode 100644 applications/demos/nqueens/nqueens-smt.cpp diff --git a/applications/demos/nqueens/nqueens-smt.cpp b/applications/demos/nqueens/nqueens-smt.cpp new file mode 100644 index 000000000..101b3a0be --- /dev/null +++ b/applications/demos/nqueens/nqueens-smt.cpp @@ -0,0 +1,209 @@ +//////////////////////////////////////////////////////////////////////// +// This file is part of Grappa, a system for scaling irregular +// applications on commodity clusters. + +// Copyright (C) 2010-2014 University of Washington and Battelle +// Memorial Institute. University of Washington authorizes use of this +// Grappa software. + +// Grappa is free software: you can redistribute it and/or modify it +// under the terms of the Affero General Public License as published +// by Affero, Inc., either version 1 of the License, or (at your +// option) any later version. + +// Grappa is distributed in the hope that it will be useful, but +// WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// Affero General Public License for more details. + +// You should have received a copy of the Affero General Public +// License along with this program. If not, you may obtain one from +// http://www.affero.org/oagpl.html. +//////////////////////////////////////////////////////////////////////// + +#include +#include + + +using namespace Grappa; +using namespace std; + + +DEFINE_int64( n, 8, "Board size" ); + +GRAPPA_DEFINE_METRIC( SimpleMetric, nqueens_runtime, 0.0 ); + + + + +/* + * Each core maintains the number of solutions it has found + the board size + */ +int64_t nqSolutions; +int nqBoardSize; +GlobalCompletionEvent gce; // tasks synchronization + + + +/* + * The main board class. + * + * The board is represented as a column array specifying the row position of the + * Queen on each column. + */ +class Board { +public: + Board(size_t size) + { + this->size = size; + columns = new int[size]; + } + + ~Board() { delete [] columns; } + + + /* + * Checks whether it is safe to put a queen in row 'row'. + */ + bool isSafe(int row) + { + /* we check if putting a queen on row 'row' will cause any of the previous + * queens (in 'columns') to capture it. */ + for (auto i=0; i +Board *clone(GlobalAddress source) +{ + /* read the remote board size */ + int remsize = delegate::call(source, [](Board &b) { return b.Size(); }); + + /* create a new board with an extra column to place the next queen */ + Board *local = new Board(remsize+1); + + /* copy the contents of the remote board to the local one */ + for (auto k=0; kSet(k, delegate::call(source, [k](Board &b) { + return b.At(k); + })); + + return local; +} + + +/* + * This is basically a brute force solution using recursion. + * + * This procedure creates a new copy of the board, adds a new column + * (with a queen at the row given by 'rowIndex') and check whether + * it is safe to add a new queen in any of the rows of the next column. + * If it is safe, it then recursively spawn new tasks to do the job. + */ +void nqSearch(SmtPtr remoteBoard, int rowIndex) +{ + /* create a new copy of remoteBoard, adding a new column */ + SmtPtr newBoard = remoteBoard.clone(); + + /* place the queen at row 'rowIndex' in the new column */ + newBoard->insertQueen(rowIndex); + + /* are we done yet? */ + if (newBoard->Size() == nqBoardSize) + nqSolutions++; // yes, solution found + else + { /* not done yet */ + + /* check whether it is safe to have a queen on row 'i' */ + for (int i=0; iisSafe(i)) { + + /* safe - spawn a new task to check for the next column */ + spawn([newBoard,i] { nqSearch(newBoard, i); }); + } + } + } +} + + +int main(int argc, char * argv[]) { + init( &argc, &argv ); + + const int expectedSolutions[] = + {0, 1, 0, 0, 2, 10, 4, 40, 92, 352, 724, 2680, 14200, 73712, 365596, \ + 2279184, 14772512}; + + nqBoardSize = FLAGS_n; + nqSolutions = 0; + + + run([=]{ + + Metrics::reset_all_cores(); + Metrics::start_tracing(); + + double start = walltime(); + + /* initial empty board */ + SmtPtr board(new Board(0)); + + finish<&gce>([board]{ + for (auto i=0; i([board,i] { nqSearch(board,i); }); + } + }); + + + int64_t total = reduce>(&nqSolutions); + + nqueens_runtime = walltime() - start; + + Metrics::stop_tracing(); + + if (nqBoardSize <= 16) { + LOG(INFO) << "NQueens (" << nqBoardSize << ") = " << total << \ + " (solution is " << (total == expectedSolutions[nqBoardSize] ? "correct)" : "wrong)"); + } + else + LOG(INFO) << "NQueens (" << nqBoardSize << ") = " << total; + + LOG(INFO) << "Elapsed time: " << nqueens_runtime.value() << " seconds"; + + Metrics::merge_and_dump_to_file(); + + }); + finalize(); +} + From f38b6e4a84a04a1eb6750c11ca12cf0104b593a8 Mon Sep 17 00:00:00 2001 From: baldas Date: Mon, 24 Nov 2014 11:40:08 -0800 Subject: [PATCH 5/7] Returned with refcnt methods. --- system/SmartPointer.hpp | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/system/SmartPointer.hpp b/system/SmartPointer.hpp index 9265589c3..112ce8ad7 100644 --- a/system/SmartPointer.hpp +++ b/system/SmartPointer.hpp @@ -82,7 +82,7 @@ class RefManager return refcnt; } -// size_t numRefs() const { return refcnt; } + size_t numRefs() const { return refcnt; } }; @@ -135,6 +135,10 @@ class SmtPtr return SmtPtr(local); } + size_t getNumRefs() + { + return delegate::call(refMan, [](RefManager *ref) { return ref->numRefs(); }); + } // destructor ~SmtPtr() From fc22b3f9a7477fee1dc474d5de1c52127943f565 Mon Sep 17 00:00:00 2001 From: baldas Date: Mon, 24 Nov 2014 11:55:31 -0800 Subject: [PATCH 6/7] New unit test for smart pointers. --- system/SmartPointer_tests.cpp | 114 ++++++++++++++++++++++++++++++++++ 1 file changed, 114 insertions(+) create mode 100644 system/SmartPointer_tests.cpp diff --git a/system/SmartPointer_tests.cpp b/system/SmartPointer_tests.cpp new file mode 100644 index 000000000..e54ff48b9 --- /dev/null +++ b/system/SmartPointer_tests.cpp @@ -0,0 +1,114 @@ +//////////////////////////////////////////////////////////////////////// +// This file is part of Grappa, a system for scaling irregular +// applications on commodity clusters. + +// Copyright (C) 2010-2014 University of Washington and Battelle +// Memorial Institute. University of Washington authorizes use of this +// Grappa software. + +// Grappa is free software: you can redistribute it and/or modify it +// under the terms of the Affero General Public License as published +// by Affero, Inc., either version 1 of the License, or (at your +// option) any later version. + +// Grappa is distributed in the hope that it will be useful, but +// WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// Affero General Public License for more details. + +// You should have received a copy of the Affero General Public +// License along with this program. If not, you may obtain one from +// http://www.affero.org/oagpl.html. +//////////////////////////////////////////////////////////////////////// + + +#include +#include +#include + +using namespace Grappa; +using namespace std; + +// dummy class +class NonPOD +{ +public: + NonPOD(size_t size): iarray(new int[size]), size(size) + { + } + + ~NonPOD() + { + delete[] iarray; + } + + int At(int i) { return iarray[i]; } + void Set(int i, int v) { iarray[i] = v; } + size_t Size() const { return size; } + +private: + int *iarray; + size_t size; + +}; + + +// clone +template<> +NonPOD *clone(GlobalAddress remoteObj) +{ + NonPOD *temp; + + int size = delegate::call(remoteObj, [](NonPOD *obj) { return obj->Size(); }); + + temp = new NonPOD(size); + for (size_t i=0; iSet(i, delegate::call(remoteObj, [i](NonPOD *obj){ return obj->At(i);})); + + return temp; +} + + +GlobalCompletionEvent gce; + +BOOST_AUTO_TEST_SUITE( SmtPtr_tests ); + + + +BOOST_AUTO_TEST_CASE( test1 ) { + + Grappa::init( GRAPPA_TEST_ARGS ); + + Grappa::run([]{ + + // create a smart pointer for a non-POD object + SmtPtr myPtr(new NonPOD(257)); + + // write something using the smart pointer + for (int i=0; iSet(i,i); + + + // spawn some tasks ... + for (int i=0; i<10; i++) + spawn([myPtr] { + // and clone the object using smart pointers + SmtPtr local = myPtr.clone(); + + // check if copy was performed correctly + BOOST_CHECK_EQUAL( local->At(mycore()), mycore() ); + //cout << "Core " << mycore() << " cloned correctly" << endl; + }); + + gce.wait(); + + // Should only have one object alive at this point + BOOST_CHECK_EQUAL( myPtr.getNumRefs(), 1 ); + + }); + Grappa::finalize(); + +} + +BOOST_AUTO_TEST_SUITE_END(); + From 1fd48b48b2a81243c4d8f24f14201897f7f33360 Mon Sep 17 00:00:00 2001 From: baldas Date: Mon, 24 Nov 2014 20:14:44 -0800 Subject: [PATCH 7/7] Performed small changes as suggested. . using #pragma once . using DVLOG(2) . changed the names of methods/functions to be more Grappa-like . More readable version of nqueens-smt --- applications/demos/nqueens/nqueens-smt.cpp | 46 +++++++++++++++------- applications/demos/nqueens/nqueens.cpp | 24 +++++------ system/CMakeLists.txt | 1 + system/SmartPointer.hpp | 32 ++++++--------- 4 files changed, 55 insertions(+), 48 deletions(-) diff --git a/applications/demos/nqueens/nqueens-smt.cpp b/applications/demos/nqueens/nqueens-smt.cpp index 101b3a0be..286d7ec3c 100644 --- a/applications/demos/nqueens/nqueens-smt.cpp +++ b/applications/demos/nqueens/nqueens-smt.cpp @@ -52,11 +52,13 @@ GlobalCompletionEvent gce; // tasks synchronization * Queen on each column. */ class Board { + const size_t MINIMUM_BOARD_SIZE = 16; /* must be > 0 */ public: Board(size_t size) { + maximum = size > MINIMUM_BOARD_SIZE ? size : MINIMUM_BOARD_SIZE; this->size = size; - columns = new int[size]; + columns = new int[maximum]; } ~Board() { delete [] columns; } @@ -77,15 +79,15 @@ class Board { return true; } - size_t Size() const { return size; } // getter method + size_t getSize() const { return size; } // getter method - // TODO: bounds checking - void Set(size_t pos, int val) + void set(size_t pos, int val) { + assert(pos < size); columns[pos] = val; } - int At(size_t pos) const + int at(size_t pos) const { assert(pos < size); return columns[pos]; @@ -94,12 +96,26 @@ class Board { // Inserts a queen in the last column at 'rowIndex' void insertQueen(int rowIndex) { - columns[size-1] = rowIndex; + if (size >= maximum) { + /* double the maximum size */ + size_t new_size = size*2; + int *new_columns = new int[new_size]; + + memcpy(new_columns, columns, size); + + maximum = new_size; + delete [] columns; + columns = new_columns; + + } + + columns[size++] = rowIndex; } private: int *columns; /* has the row position for the queen on each column */ size_t size; /* board size */ + size_t maximum; /* maximum size before resizing */ }; @@ -107,15 +123,15 @@ template<> Board *clone(GlobalAddress source) { /* read the remote board size */ - int remsize = delegate::call(source, [](Board &b) { return b.Size(); }); + int remsize = delegate::call(source, [](Board &b) { return b.getSize(); }); - /* create a new board with an extra column to place the next queen */ - Board *local = new Board(remsize+1); + /* create a new board */ + Board *local = new Board(remsize); /* copy the contents of the remote board to the local one */ for (auto k=0; kSet(k, delegate::call(source, [k](Board &b) { - return b.At(k); + local->set(k, delegate::call(source, [k](Board &b) { + return b.at(k); })); return local; @@ -130,7 +146,7 @@ Board *clone(GlobalAddress source) * it is safe to add a new queen in any of the rows of the next column. * If it is safe, it then recursively spawn new tasks to do the job. */ -void nqSearch(SmtPtr remoteBoard, int rowIndex) +void nq_search(SmtPtr remoteBoard, int rowIndex) { /* create a new copy of remoteBoard, adding a new column */ SmtPtr newBoard = remoteBoard.clone(); @@ -139,7 +155,7 @@ void nqSearch(SmtPtr remoteBoard, int rowIndex) newBoard->insertQueen(rowIndex); /* are we done yet? */ - if (newBoard->Size() == nqBoardSize) + if (newBoard->getSize() == nqBoardSize) nqSolutions++; // yes, solution found else { /* not done yet */ @@ -150,7 +166,7 @@ void nqSearch(SmtPtr remoteBoard, int rowIndex) if (newBoard->isSafe(i)) { /* safe - spawn a new task to check for the next column */ - spawn([newBoard,i] { nqSearch(newBoard, i); }); + spawn([newBoard,i] { nq_search(newBoard, i); }); } } } @@ -181,7 +197,7 @@ int main(int argc, char * argv[]) { finish<&gce>([board]{ for (auto i=0; i([board,i] { nqSearch(board,i); }); + spawn([board,i] { nq_search(board,i); }); } }); diff --git a/applications/demos/nqueens/nqueens.cpp b/applications/demos/nqueens/nqueens.cpp index 0890df253..b1367668d 100644 --- a/applications/demos/nqueens/nqueens.cpp +++ b/applications/demos/nqueens/nqueens.cpp @@ -83,7 +83,7 @@ class Board { } /* Called whenever the object must be erased (i.e., memory freed) */ - void Release() { if (!--ref_count) delete[] columns; } + void release() { if (!--ref_count) delete[] columns; } /* * Checks whether it is safe to put a queen in row 'row'. @@ -101,9 +101,9 @@ class Board { } /* Called explitictly whenever the object is copied. */ - void Shared() { ref_count++; } + void shared() { ref_count++; } - size_t Size() const { return size; } // getter method + size_t getSize() const { return size; } // getter method private: int *columns; /* has the row position for the queen on each column */ @@ -121,13 +121,13 @@ class Board { * of the rows of the next column. In such cases a new task is spawned * recursively for the next column. */ -void nqSearch(GlobalAddress remoteBoard, int rowIndex) +void nq_search(GlobalAddress remoteBoard, int rowIndex) { /* create a new copy of remoteBoard, adding a new column */ Board *newBoard = new Board(remoteBoard, rowIndex); /* are we done yet? */ - if (newBoard->Size() == nqBoardSize) + if (newBoard->getSize() == nqBoardSize) nqSolutions++; // yes, solution found else { /* not done yet */ @@ -141,18 +141,18 @@ void nqSearch(GlobalAddress remoteBoard, int rowIndex) /* safe - spawn a new task to check for the next column */ - newBoard->Shared(); // board is being shared + newBoard->shared(); // board is being shared /* spawn a recursive search */ - spawn([g_newBoard,i] { nqSearch(g_newBoard, i); }); + spawn([g_newBoard,i] { nq_search(g_newBoard, i); }); } } } /* don't need the remote board anymore: try to delete it */ - delegate::call(remoteBoard, [](Board &b) { b.Release(); }); + delegate::call(remoteBoard, [](Board &b) { b.release(); }); - newBoard->Release(); + newBoard->release(); } @@ -181,12 +181,12 @@ int main(int argc, char * argv[]) { finish<&gce>([g_board,board]{ for (auto i=0; iShared(); - spawn([g_board,i] { nqSearch(g_board,i); }); + board->shared(); + spawn([g_board,i] { nq_search(g_board,i); }); } }); - board->Release(); + board->release(); int64_t total = reduce>(&nqSolutions); diff --git a/system/CMakeLists.txt b/system/CMakeLists.txt index 402e62d54..c9d5d400d 100644 --- a/system/CMakeLists.txt +++ b/system/CMakeLists.txt @@ -226,6 +226,7 @@ add_check( ThreadQueue_tests.cpp 2 1 pass ) add_check( graph/Graph_tests.cpp 2 1 pass ) +add_check( SmartPointer_tests.cpp 4 2 pass ) # # begin hack for dealing with communicator test diff --git a/system/SmartPointer.hpp b/system/SmartPointer.hpp index 112ce8ad7..9a0570d69 100644 --- a/system/SmartPointer.hpp +++ b/system/SmartPointer.hpp @@ -22,22 +22,14 @@ //////////////////////////////////////////////////////////////////////// -#ifndef _SMTPTR_HPP__ -#define _SMTPTR_HPP__ +#pragma once #include using namespace Grappa; -#if 0 -# include -using namespace std; -# define DPRINT(m) cout << setw(14) << (this) << ": " << m << endl -# define DPRINT2(m,n) cout << setw(14) << (this) << ": " << m << n << endl -#else -# define DPRINT(m) -# define DPRINT2(m,n) -#endif +# define DPRINT(m) DVLOG(2) << (this) << ": " << m << std::endl +# define DPRINT2(m,n) DVLOG(2) << (this) << ": " << m << n << std::endl /* * Reference manager class. @@ -65,13 +57,13 @@ class RefManager T& getRef() { return *ptr; } T* getPtr() { return ptr; } - void Increment() + void increment() { refcnt++; DPRINT2(" -> RefManager incremented: ", refcnt); } - size_t Decrement() + size_t decrement() { refcnt--; DPRINT2(" -> RefManager decremented: ", refcnt); @@ -113,7 +105,7 @@ class SmtPtr { DPRINT("*** SmtPtr copy constructor ***"); - delegate::call(refMan, [](RefManager *ref) { ref->Increment(); }); + delegate::call(refMan, [](RefManager *rm) { rm->increment(); }); } // T& operator*() { return reference_->getRef(); } @@ -129,24 +121,23 @@ class SmtPtr { DPRINT(" -> SmtPtr clone"); - T *local = ::clone(delegate::call(refMan, [](RefManager *ref) - { return make_global(ref->getPtr()); })); + T *local = ::clone(delegate::call(refMan, [](RefManager *rm) + { return make_global(rm->getPtr()); })); return SmtPtr(local); } size_t getNumRefs() { - return delegate::call(refMan, [](RefManager *ref) { return ref->numRefs(); }); + return delegate::call(refMan, [](RefManager *rm) { return rm->numRefs(); }); } // destructor ~SmtPtr() { DPRINT("*** SmtPtr destructor ***"); - - RefManager *ref = (RefManager *)refMan.pointer(); - delegate::call(refMan.core(), [ref] { if (!ref->Decrement()) delete ref; }); + + delegate::call(refMan, [](RefManager *rm) { if (!rm->decrement()) delete rm; }); } }; @@ -154,4 +145,3 @@ class SmtPtr -#endif /* _SMTPTR_HPP_ */