Add Read\Write Lock for TGitCache to reduce crash
[TortoiseGit.git] / src / Git / SharedMutex.h
blobd9e48f3c03a6c840a3ed3c184c1ed110d3bef047
1 /**
2 * SharedMutex.h
3 * @Author Tu Yongce <yongce (at) 126 (dot) com>
4 * @Created 2008-11-17
5 * @Modified 2008-11-17
6 * @Version 0.1
7 */
9 #ifndef SHARED_MUTEX_H_INCLUDED
10 #define SHARED_MUTEX_H_INCLUDED
12 #ifndef _WIN32
13 #error "works only on Windows"
14 #endif
16 #include <windows.h>
18 // ¿É¹²ÏíµÄ»¥³âÁ¿
19 class SharedMutex
21 private:
22 HANDLE m_mutex;
23 HANDLE m_sharedEvent;
24 HANDLE m_exclusiveEvent;
26 volatile int m_sharedNum;
27 volatile int m_exclusiveNum;
28 volatile int m_lockType;
30 static const int LOCK_NONE = 0;
31 static const int LOCK_SHARED = 1;
32 static const int LOCK_EXCLUSIVE = 2;
34 public:
35 SharedMutex();
36 void Init();
37 void Release();
38 // SharedMutex(SharedMutex &mutex);
39 // SharedMutex & operator = (SharedMutex &mutex);
41 ~SharedMutex();
43 // »ñÈ¡¹²Ïí·ÃÎÊȨ
44 bool AcquireShared(DWORD waitTime = INFINITE);
45 // ÊͷŹ²Ïí·ÃÎÊȨ
46 void ReleaseShared();
48 // »ñÈ¡¶ÀÕ¼·ÃÎÊȨ
49 bool AcquireExclusive(DWORD waitTime = INFINITE);
50 // ÊͷŶÀÕ¼·ÃÎÊȨ
51 void ReleaseExclusive();
54 #endif // SHARED_MUTEX_H_INCLUDED