code reorg
[csql.git] / include / Mutex.h
blob31c07b6a882cfdca5f59b58f4a4b5e40e76dc2cd
1 /***************************************************************************
2 * *
3 * Copyright (C) Lakshya Solutions Ltd. All rights reserved. *
4 * *
5 ***************************************************************************/
7 #ifndef MUTEX_H
8 #define MUTEX_H
9 #include<os.h>
10 typedef int Lock;
11 class DllExport Mutex
14 #if defined(sparc) || defined(i686) || defined (x86_64)
15 volatile Lock lock;
16 #else
17 pthread_mutex_t mutex_;
18 #endif
19 public:
20 char name[20];
21 int pSlot;
22 Mutex();
23 int init();
24 int init(char *name);
25 int tryLock(int tries=0, int waitmsecs=0);
26 int getLock(int procSlot, bool procAccount=true);
27 int releaseLock(int procSlot, bool procAccount=true);
28 int tryShareLock(int tries=0, int waitmsecs=0,bool share=false,bool upgrade=false);
29 int getShareLock(int procSlot, bool procAccount=true);
30 int getExclusiveLock(int procSlot, bool procAccount=true,bool upgrade=false);
31 int releaseShareLock(int procSlot, bool procAccount=true);
32 int destroy();
33 int recoverMutex();
34 static int CASGen(volatile void *ptr, InUse oldVal, InUse newVal);
35 static int CASL(volatile long *ptr, long oldVal, long newVal);
36 static int CAS(volatile int *ptr, int oldVal, int newVal);
37 int getLockVal(){ return lock; }
38 void print() {
39 printf("<MUTEX name=%s lock=%d pslot=%d> </MUTEX>\n", name, lock,pSlot);
43 #endif