Ref counting
[iotcloud.git] / version2 / src / C / ArbitrationRound.cc
index 159aeaea39ccb1bcac682154a4469b2046407c53..cc316f0578ab91d8e5aadc3298b549d34fae4872 100644 (file)
@@ -1,5 +1,6 @@
 #include "ArbitrationRound.h"
 #include "Commit.h"
+#include "CommitPart.h"
 
 ArbitrationRound::ArbitrationRound(Commit *_commit, Hashset<Abort *> *_abortsBefore) :
        abortsBefore(_abortsBefore),
@@ -19,6 +20,11 @@ ArbitrationRound::ArbitrationRound(Commit *_commit, Hashset<Abort *> *_abortsBef
 
 ArbitrationRound::~ArbitrationRound() {
        delete abortsBefore;
+       uint partsSize = parts->size();
+       for (uint i = 0; i < partsSize; i++) {
+               Entry * part = parts->get(i);
+               part->releaseRef();
+       }
        delete parts;
        if (commit != NULL)
                delete commit;
@@ -28,6 +34,11 @@ void ArbitrationRound::generateParts() {
        if (didGenerateParts) {
                return;
        }
+       uint partsSize = parts->size();
+       for (uint i = 0; i < partsSize; i++) {
+               Entry * part = parts->get(i);
+               part->releaseRef();
+       }
        parts->clear();
        SetIterator<Abort *, Abort *> *abit = abortsBefore->iterator();
        while (abit->hasNext())
@@ -37,7 +48,9 @@ void ArbitrationRound::generateParts() {
                Vector<CommitPart *> *cParts = commit->getParts();
                uint cPartsSize = cParts->size();
                for (uint i = 0; i < cPartsSize; i++) {
-                       parts->add((Entry *)cParts->get(i));
+                       CommitPart * part = cParts->get(i);
+                       part->acquireRef();
+                       parts->add((Entry *)part);
                }
        }
 }
@@ -47,7 +60,12 @@ Vector<Entry *> *ArbitrationRound::getParts() {
 }
 
 void ArbitrationRound::removeParts(Vector<Entry *> *removeParts) {
-       parts->removeAll(removeParts);
+       uint size = removeParts->size();
+       for(uint i=0; i < size; i++) {
+               Entry * e = removeParts->get(i);
+               if (parts->remove(e))
+                       e->releaseRef();
+       }
        didSendPart = true;
 }