windows porting first phase- ported os layer, storage module to windows
[csql.git] / include / Mutex.h
blobdd4057c5b0354ac4d4d904f249637632bc052328
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 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 upgrade=false);
28 int getShareLock(int procSlot, bool procAccount=true);
29 int getExclusiveLock(int procSlot, bool procAccount=true,bool upgrade=false);
30 int releaseShareLock(int procSlot, bool procAccount=true);
31 int destroy();
32 int recoverMutex();
33 static int CASGen(void *ptr, InUse oldVal, InUse newVal);
34 static int CASL(long *ptr, long oldVal, long newVal);
35 static int CAS(int *ptr, int oldVal, int newVal);
36 int getLockVal(){ return lock; }
37 void print() {
38 printf("Mutex: %d %s\n", lock, name);
42 #endif