1 /* |
|
2 * Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies). |
|
3 * All rights reserved. |
|
4 * This component and the accompanying materials are made available |
|
5 * under the terms of "Eclipse Public License v1.0" |
|
6 * which accompanies this distribution, and is available |
|
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
8 * |
|
9 * Initial Contributors: |
|
10 * Nokia Corporation - initial contribution. |
|
11 * |
|
12 * Contributors: |
|
13 * |
|
14 * Description: |
|
15 * This file contains headers of synchronziation objects. These classes are Mutex, Semaphore and |
|
16 * Event classes. Implementation of TimeoutException is defined. |
|
17 */ |
|
18 |
|
19 #ifndef SYNC_H |
|
20 #define SYNC_H |
|
21 |
|
22 #include <windows.h> |
|
23 #include <process.h> |
|
24 |
|
25 #include <string> |
|
26 |
|
27 using namespace std; |
|
28 |
|
29 //********************************************************************************** |
|
30 // Class TimeoutException |
|
31 // |
|
32 //********************************************************************************** |
|
33 |
|
34 class TimeoutException |
|
35 { |
|
36 public: |
|
37 TimeoutException(const char* s = "") { m_Message.assign(s); } |
|
38 const string& GetMessage() const { return m_Message; } |
|
39 private: |
|
40 string m_Message; |
|
41 }; |
|
42 |
|
43 //********************************************************************************** |
|
44 // Class Mutex |
|
45 // |
|
46 // This class implements a Mutex using Windows API synchronization mechanism |
|
47 //********************************************************************************** |
|
48 |
|
49 |
|
50 class Mutex |
|
51 { |
|
52 public: |
|
53 Mutex(void); |
|
54 ~Mutex(void); |
|
55 void Lock(void); |
|
56 void Unlock(void); |
|
57 private: |
|
58 CRITICAL_SECTION m_Lock; |
|
59 }; |
|
60 |
|
61 //********************************************************************************** |
|
62 // Class Semaphore |
|
63 // |
|
64 // This class encapsulates Windows API Semaphore functionality |
|
65 //********************************************************************************** |
|
66 |
|
67 class Semaphore |
|
68 { |
|
69 public: |
|
70 Semaphore(void); |
|
71 Semaphore(int available); |
|
72 ~Semaphore(void); |
|
73 DWORD Wait(DWORD timeout = INFINITE); |
|
74 void Notify(void); |
|
75 void Notify(int how_many); |
|
76 private: |
|
77 HANDLE m_Semaphore; |
|
78 }; |
|
79 |
|
80 //********************************************************************************** |
|
81 // Class Event |
|
82 // |
|
83 // This class encapsulates Windows API Event functionality |
|
84 //********************************************************************************** |
|
85 |
|
86 class Event |
|
87 { |
|
88 public: |
|
89 Event(bool manual_reset = false); |
|
90 ~Event(void); |
|
91 void Set(void); |
|
92 void Reset(void); |
|
93 DWORD Wait(DWORD timeout = INFINITE); |
|
94 HANDLE EventHandle() const; |
|
95 private: |
|
96 HANDLE m_Event; |
|
97 }; |
|
98 |
|
99 #endif |
|
100 |
|
101 // End of the file |
|