mirror of
https://github.com/HifiExperiments/overte.git
synced 2025-08-04 15:13:10 +02:00
add a clear method to the NodeList to delete all nodes
This commit is contained in:
parent
dc59f6deb5
commit
8ed518c4a2
2 changed files with 18 additions and 0 deletions
|
@ -70,6 +70,9 @@ NodeList::NodeList(char newOwnerType, unsigned int newSocketListenPort) :
|
|||
NodeList::~NodeList() {
|
||||
delete _nodeTypesOfInterest;
|
||||
|
||||
// delete the nodes in our list
|
||||
clear();
|
||||
|
||||
// stop the spawned threads, if they were started
|
||||
stopSilentNodeRemovalThread();
|
||||
stopPingUnknownNodesThread();
|
||||
|
@ -203,6 +206,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;
|
||||
|
||||
|
|
|
@ -67,6 +67,8 @@ public:
|
|||
int size() { return _numNodes; }
|
||||
int getNumAliveNodes() const;
|
||||
|
||||
void clear();
|
||||
|
||||
void lock() { pthread_mutex_lock(&mutex); }
|
||||
void unlock() { pthread_mutex_unlock(&mutex); }
|
||||
|
||||
|
|
Loading…
Reference in a new issue