include/Lock.h

Go to the documentation of this file.
00001 /***************************************************************************
00002  *   Copyright (C) 2007 by www.databasecache.com                           *
00003  *   Contact: praba_tuty@databasecache.com                                 *
00004  *                                                                         *
00005  *   This program is free software; you can redistribute it and/or modify  *
00006  *   it under the terms of the GNU General Public License as published by  *
00007  *   the Free Software Foundation; either version 2 of the License, or     *
00008  *   (at your option) any later version.                                   *
00009  *                                                                         *
00010  *   This program is distributed in the hope that it will be useful,       *
00011  *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
00012  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
00013  *   GNU General Public License for more details.                          *
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     //-1 indicates write lock is taken
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 //singleton
00073 //DatabaseManager has this object and give reference to it to
00074 //Table interface and so on.
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

Generated on Mon Jun 9 22:37:14 2008 for csql by  doxygen 1.4.7