allocator fixes
[csql.git] / include / Mutex.h
blob068a3f9b685367d2aa9981e358673829f411d58c
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 Mutex
14 #if defined(sparc) || defined(i686) || defined (x86_64)
15 Lock lock;
16 #else
17 pthread_mutex_t mutex_;
18 #endif
19 public:
20 char name[20];
21 Mutex();
22 int init();
23 int init(char *name);
24 int tryLock(int tries=0, int waitmsecs=0);
25 int getLock(int procSlot, bool procAccount=true);
26 int releaseLock(int procSlot, bool procAccount=true);
27 int tryShareLock(int tries=0, int waitmsecs=0,bool share=false,bool isDelete=false);
28 int getShareLock(int procSlot, bool procAccount=true);
29 int getExclusiveLock(int procSlot, bool procAccount=true,bool isDelete=false);
30 int releaseShareLock(int procSlot, bool procAccount=true);
31 int destroy();
32 int recoverMutex();
33 static int CASL(long *ptr, long oldVal, long newVal);
34 static int CAS(int *ptr, int oldVal, int newVal);
35 int getLockVal(){ return lock; }
36 void print() {
37 printf("Mutex: %d %s\n", lock, name);
41 #endif