Ref counting
[iotcloud.git] / version2 / src / C / CommitPart.h
index 34341c7c39d3cd1deb2b1bf5a0e65b413812e1ec..7b8be2e8450c76c67a8aa096be23680b73e57706 100644 (file)
@@ -2,40 +2,44 @@
 #define COMMITPART_H
 #include "common.h"
 #include "Entry.h"
+#include "Pair.h"
 
 // Max size of the part excluding the fixed size header
 #define CommitPart_MAX_NON_HEADER_SIZE 512
 
 class CommitPart : public Entry {
- private:
+private:
        // Sequence number of the transaction this commit is for, -1 if not a cloud transaction
        int64_t machineId;              // Machine Id of the device that made the commit
        int64_t sequenceNumber; // commit sequence number for this arbitrator
        int64_t transactionSequenceNumber;
        int32_t partNumber;     // Parts position in the
-       bool isLastPart;
-       Array<char> * data;
-       
-       Pair<int64_t int32_t> * partId;
-       Pair<int64_t, int64_t> * commitId;
-       
- public:
-       CommitPart(Slot *s, int64_t _machineId, int64_t _sequenceNumber, int64_t _transactionSequenceNumber, int _partNumber, Array<char>* _data, bool _isLastPart);
+       bool fldisLastPart;
+       int32_t refCount;
+       Array<char> *data;
+
+       Pair<int64_t, int32_t> partId;
+       Pair<int64_t, int64_t> commitId;
+
+public:
+       CommitPart(Slot *s, int64_t _machineId, int64_t _sequenceNumber, int64_t _transactionSequenceNumber, int _partNumber, Array<char> *_data, bool _isLastPart);
+       ~CommitPart();
        int getSize();
-       void setSlot(Slot *s);
        int getPartNumber();
        int getDataSize();
-       Array<char> * getData();
-       Pair<int64_t int32_t> * getPartId();
-       Pair<int64_t, int64_t> getCommitId();
+       Array<char> *getData();
+       Pair<int64_t, int32_t> * getPartId();
+       Pair<int64_t, int64_t> getCommitId();
        bool isLastPart();
        int64_t getMachineId();
        int64_t getTransactionSequenceNumber();
        int64_t getSequenceNumber();
        void encode(ByteBuffer *bb);
        char getType();
-       Entry* getCopy(Slot *s);
+       Entry *getCopy(Slot *s);
+       void releaseRef() {if ((--refCount)==0) delete this;}   
+       void acquireRef() {refCount++;}
 };
 
-Entry * CommitPart_decode(Slot * s, ByteBuffer *bb);
+Entry *CommitPart_decode(Slot *s, ByteBuffer *bb);
 #endif