Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code

Side by Side Diff: src/Thread.h

Issue 10026001: Cross-platform thread primitives (Closed)
Patch Set: Don't unlock/signal mutices/conditions, move Mutex and Condition to the top level Created April 4, 2013, 2:52 a.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | src/Thread.cpp » ('j') | test/Thread.cpp » ('J')
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 #ifndef ADBLOCKPLUS_THREAD_H 1 #ifndef ADBLOCKPLUS_THREAD_H
2 #define ADBLOCKPLUS_THREAD_H 2 #define ADBLOCKPLUS_THREAD_H
3 3
4 #ifdef WIN32 4 #ifdef WIN32
5 #include <windows.h> 5 #include <windows.h>
6 #else 6 #else
7 #include <pthread.h> 7 #include <pthread.h>
8 #endif 8 #endif
9 9
10 namespace AdblockPlus 10 namespace AdblockPlus
11 { 11 {
12 class Mutex
13 {
14 public:
15 #ifdef WIN32
16 CRITICAL_SECTION nativeMutex;
17 #else
18 pthread_mutex_t nativeMutex;
19 #endif
20
21 Mutex();
22 ~Mutex();
23 void Lock();
24 void Unlock();
25 };
26
27 class ConditionVariable
28 {
29 public:
30 ConditionVariable();
31 ~ConditionVariable();
32 void Wait(Mutex& mutex);
33 void Signal();
34
35 private:
36 #ifdef WIN32
37 CONDITION_VARIABLE nativeCondition;
38 #else
39 pthread_cond_t nativeCondition;
40 #endif
41 };
42
12 class Thread 43 class Thread
13 { 44 {
14 public: 45 public:
15 class Mutex
16 {
17 public:
18 #ifdef WIN32
19 CRITICAL_SECTION nativeMutex;
20 #else
21 pthread_mutex_t nativeMutex;
22 #endif
23
24 Mutex();
25 ~Mutex();
26 void Lock();
27 void Unlock();
28 };
29
30 class Condition
31 {
32 public:
33 Condition();
34 ~Condition();
35 void Wait(Mutex& mutex);
36 void Signal();
37
38 private:
39 #ifdef WIN32
40 CONDITION_VARIABLE nativeCondition;
41 #else
42 pthread_cond_t nativeCondition;
43 #endif
44 };
45
46 virtual ~Thread(); 46 virtual ~Thread();
47 virtual void Run() = 0; 47 virtual void Run() = 0;
48 void Start(); 48 void Start();
49 void Join(); 49 void Join();
50 50
51 private: 51 private:
52 #ifdef WIN32 52 #ifdef WIN32
53 HANDLE thread; 53 HANDLE nativeThread;
54 #else 54 #else
55 pthread_t thread; 55 pthread_t nativeThread;
56 #endif 56 #endif
57 }; 57 };
58 } 58 }
59 59
60 #endif 60 #endif
OLDNEW
« no previous file with comments | « no previous file | src/Thread.cpp » ('j') | test/Thread.cpp » ('J')

Powered by Google App Engine
This is Rietveld