1974906 show tables command dumps core when csqlserver is not runnin
[csql.git] / include / Lock.h
blob7cc266ef8a073b248f5772ca1c0f6decba57a79d
1 /***************************************************************************
2 * Copyright (C) 2007 by www.databasecache.com *
3 * Contact: praba_tuty@databasecache.com *
4 * *
5 * This program is free software; you can redistribute it and/or modify *
6 * it under the terms of the GNU General Public License as published by *
7 * the Free Software Foundation; either version 2 of the License, or *
8 * (at your option) any later version. *
9 * *
10 * This program is distributed in the hope that it will be useful, *
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
13 * GNU General Public License for more details. *
14 * *
15 ***************************************************************************/
16 #ifndef LOCK_H
17 #define LOCK_H
18 #include<os.h>
19 #include<Index.h>
20 class Chunk;
21 class Database;
22 class Transaction;
24 class LockInfo
26 public:
27 signed int noOfReaders_;
28 //-1 indicates write lock is taken
30 unsigned char waitReaders_;
31 unsigned char waitWriters_;
32 LockInfo() { noOfReaders_ = 0; waitReaders_ = 0; waitWriters_ = 0; }
36 class LockHashNode
38 public:
39 void *ptrToTuple_;
40 LockInfo lInfo_;
41 LockHashNode *next_;
42 void print()
44 printf("<Lock Node>\n");
45 printf(" <Tuple> %x </Tuple>\n", ptrToTuple_);
46 printf(" <NoOfReaders> %d </NoOfReaders>\n", lInfo_.noOfReaders_);
47 printf(" <WaitReaders> %x </WaitReaders>\n", lInfo_.waitReaders_);
48 printf(" <WaitWriters> %x </WaitWriters>\n", lInfo_.waitWriters_);
49 printf("</Lock Node>\n");
53 class LockListIter
55 LockHashNode *iter;
56 public:
57 LockListIter(){}
58 LockListIter(LockHashNode *head) { iter = head;}
59 LockHashNode* next();
60 friend class LockList;
63 class TransHasNode
65 public:
66 LockHashNode *node_;
67 TransHasNode *next_;
68 void print() { node_->print(); }
71 class DatabaseManagerImpl;
72 //singleton
73 //DatabaseManager has this object and give reference to it to
74 //Table interface and so on.
75 class LockManager
77 public:
78 Database *systemDatabase_;
80 private:
81 LockHashNode* allocLockNode(LockInfo &info, void *tuple);
82 void deallocLockNode(LockHashNode *head, Bucket *bucket);
83 Bucket* getLockBucket(void *tuple);
85 public:
87 LockManager(Database *sysDb_){ systemDatabase_ = sysDb_;}
88 DbRetVal getSharedLock(void *tuple, Transaction **trans);
89 DbRetVal getExclusiveLock(void * tuple, Transaction **trans);
90 DbRetVal releaseLock(void *tuple);
91 DbRetVal isExclusiveLocked(void *tuple, Transaction **trans, bool &status);
92 void printUsageStatistics();
93 void printDebugInfo();
97 #endif