00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016 #ifndef LOCK_H
00017 #define LOCK_H
00018 #include<os.h>
00019 #include<Index.h>
00020 class Chunk;
00021 class Database;
00022 class Transaction;
00023
00024 class LockInfo
00025 {
00026 public:
00027 signed int noOfReaders_;
00028
00029
00030 unsigned char waitReaders_;
00031 unsigned char waitWriters_;
00032 LockInfo() { noOfReaders_ = 0; waitReaders_ = 0; waitWriters_ = 0; }
00033
00034 };
00035
00036 class LockHashNode
00037 {
00038 public:
00039 void *ptrToTuple_;
00040 LockInfo lInfo_;
00041 LockHashNode *next_;
00042 void print()
00043 {
00044 printf("<Lock Node>\n");
00045 printf(" <Tuple> %x </Tuple>\n", ptrToTuple_);
00046 printf(" <NoOfReaders> %d </NoOfReaders>\n", lInfo_.noOfReaders_);
00047 printf(" <WaitReaders> %x </WaitReaders>\n", lInfo_.waitReaders_);
00048 printf(" <WaitWriters> %x </WaitWriters>\n", lInfo_.waitWriters_);
00049 printf("</Lock Node>\n");
00050 }
00051 };
00052
00053 class LockListIter
00054 {
00055 LockHashNode *iter;
00056 public:
00057 LockListIter(){}
00058 LockListIter(LockHashNode *head) { iter = head;}
00059 LockHashNode* next();
00060 friend class LockList;
00061 };
00062
00063 class TransHasNode
00064 {
00065 public:
00066 LockHashNode *node_;
00067 TransHasNode *next_;
00068 void print() { node_->print(); }
00069 };
00070
00071 class DatabaseManagerImpl;
00072
00073
00074
00075 class LockManager
00076 {
00077 public:
00078 Database *systemDatabase_;
00079
00080 private:
00081 LockHashNode* allocLockNode(LockInfo &info, void *tuple, DbRetVal *rv);
00082 void deallocLockNode(LockHashNode *head, Bucket *bucket);
00083 Bucket* getLockBucket(void *tuple);
00084
00085 public:
00086
00087 LockManager(Database *sysDb_){ systemDatabase_ = sysDb_;}
00088 DbRetVal getSharedLock(void *tuple, Transaction **trans);
00089 DbRetVal getExclusiveLock(void * tuple, Transaction **trans);
00090 DbRetVal releaseLock(void *tuple);
00091 DbRetVal isExclusiveLocked(void *tuple, Transaction **trans, bool &status);
00092 void printUsageStatistics();
00093 void printDebugInfo();
00094 };
00095
00096
00097 #endif