equal
deleted
inserted
replaced
|
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 the License "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 * |
|
16 */ |
|
17 |
|
18 #include "stdafx.h" |
|
19 #include "mutex.h" |
|
20 |
|
21 Mutex::Mutex() |
|
22 { |
|
23 m_hMutex = NULL; |
|
24 m_waitTimeout = 0L; |
|
25 m_mutexOpen = FALSE; |
|
26 } |
|
27 Mutex::~Mutex() |
|
28 { |
|
29 Close(); |
|
30 } |
|
31 |
|
32 BOOL Mutex::Open(CHAR *mutexName, DWORD waitTimeout) |
|
33 { |
|
34 #ifdef WIN32 |
|
35 m_hMutex = ::CreateMutex(NULL, FALSE, mutexName); |
|
36 #else |
|
37 #error non Win32 |
|
38 #endif |
|
39 if (m_hMutex == NULL) |
|
40 m_mutexOpen = FALSE; |
|
41 else |
|
42 { |
|
43 m_mutexOpen = TRUE; |
|
44 m_waitTimeout = waitTimeout; |
|
45 } |
|
46 |
|
47 return m_mutexOpen; |
|
48 } |
|
49 void Mutex::Close() |
|
50 { |
|
51 if (m_mutexOpen) |
|
52 { |
|
53 #ifdef WIN32 |
|
54 ::ReleaseMutex(m_hMutex); |
|
55 ::CloseHandle(m_hMutex); |
|
56 #else |
|
57 #error non WIN32 |
|
58 #endif |
|
59 m_hMutex = NULL; |
|
60 m_mutexOpen = FALSE; |
|
61 } |
|
62 } |
|
63 BOOL Mutex::Wait() |
|
64 { |
|
65 #ifdef WIN32 |
|
66 DWORD dwWaitResult = ::WaitForSingleObject(m_hMutex, m_waitTimeout); |
|
67 if (dwWaitResult == WAIT_OBJECT_0) |
|
68 { |
|
69 return TRUE; |
|
70 } |
|
71 return FALSE; |
|
72 #else |
|
73 #error non WIN32 |
|
74 #endif |
|
75 } |
|
76 BOOL Mutex::Release() |
|
77 { |
|
78 BOOL ret = FALSE; |
|
79 #ifdef WIN32 |
|
80 ret = ::ReleaseMutex(m_hMutex); |
|
81 #else |
|
82 #error non WIN32 |
|
83 #endif |
|
84 |
|
85 return ret; |
|
86 } |