1 /* 2 * Copyright 2017, Chế Vũ Gia Hy, cvghy116@gmail.com. 3 * Copyright 2001-2012, Axel Dörfler, axeld@pinc-software.de. 4 * This file may be used under the terms of the MIT License. 5 */ 6 #ifndef JOURNAL_H 7 #define JOURNAL_H 8 9 10 #include "Volume.h" 11 12 class Transaction; 13 14 15 class Journal { 16 public: 17 Journal(Volume* volume); 18 ~Journal(); 19 20 Volume* GetVolume() const { return fVolume; } 21 Transaction* CurrentTransaction() const { return fOwner; } 22 uint64 SystemTransactionID() const 23 { return fCurrentGeneration; } 24 int32 TransactionID() const { return fTransactionID; } 25 status_t Lock(Transaction* owner); 26 status_t UnLock(Transaction* owner, bool success); 27 28 private: 29 static void _TransactionWritten(int32 transactionID, int32 event, 30 void* _journal); 31 status_t _TransactionDone(bool success); 32 33 private: 34 Volume* fVolume; 35 recursive_lock fLock; 36 Transaction* fOwner; 37 int32 fTransactionID; 38 uint64 fCurrentGeneration; 39 }; 40 41 42 class Transaction { 43 public: 44 Transaction(Volume* volume); 45 Transaction(); 46 ~Transaction(); 47 48 Journal* GetJournal() const { return fJournal; } 49 int32 ID() const { return fJournal->TransactionID(); } 50 uint64 SystemID() const 51 { return fJournal->SystemTransactionID(); } 52 bool HasBlock(fsblock_t blockNumber) const; 53 Transaction* Parent() const { return fParent; } 54 void SetParent(Transaction* parent) { fParent = parent; } 55 status_t Start(Volume* volume); 56 status_t Done(); 57 private: 58 Journal* fJournal; 59 Transaction* fParent; 60 }; 61 62 63 #endif // JOURNAL_H 64