add method to clear the NodeList

This commit is contained in:
Stephen Birarda 2013-07-15 14:30:13 -07:00
parent 4f0e472868
commit 12697c6b14
2 changed files with 17 additions and 0 deletions

View file

@ -70,6 +70,8 @@ NodeList::NodeList(char newOwnerType, unsigned int newSocketListenPort) :
NodeList::~NodeList() {
delete _nodeTypesOfInterest;
clear();
// stop the spawned threads, if they were started
stopSilentNodeRemovalThread();
@ -209,6 +211,19 @@ int NodeList::getNumAliveNodes() const {
return numAliveNodes;
}
void NodeList::clear() {
// delete all of the nodes in the list, set the pointers back to NULL and the number of nodes to 0
for (int i = 0; i < _numNodes; i++) {
Node** nodeBucket = _nodeBuckets[i / NODES_PER_BUCKET];
Node* node = nodeBucket[i % NODES_PER_BUCKET];
delete node;
node = NULL;
}
_numNodes = 0;
}
void NodeList::setNodeTypesOfInterest(const char* nodeTypesOfInterest, int numNodeTypesOfInterest) {
delete _nodeTypesOfInterest;

View file

@ -65,6 +65,8 @@ public:
int size() { return _numNodes; }
int getNumAliveNodes() const;
void clear();
void lock() { pthread_mutex_lock(&mutex); }
void unlock() { pthread_mutex_unlock(&mutex); }