1 /*  Copyright (c) MediaArea.net SARL. All Rights Reserved.
2  *
3  *  Use of this source code is governed by a zlib-style license that can
4  *  be found in the License.txt file in the root of the source tree.
5  */
6 
7 //---------------------------------------------------------------------------
8 #include "ZenLib/PreComp.h"
9 #ifdef __BORLANDC__
10     #pragma hdrstop
11 #endif
12 //---------------------------------------------------------------------------
13 
14 //---------------------------------------------------------------------------
15 #include "ZenLib/Conf_Internal.h"
16 //---------------------------------------------------------------------------
17 
18 //---------------------------------------------------------------------------
19 #include "ZenLib/CriticalSection.h"
20 //---------------------------------------------------------------------------
21 
22 //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
23 //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
24 // ZENLIB_USEWX
25 //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
26 //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
27 #ifdef ZENLIB_USEWX
28 //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
29 //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
30 
31 //---------------------------------------------------------------------------
32 #include <wx/thread.h>
33 //---------------------------------------------------------------------------
34 
35 namespace ZenLib
36 {
37 
38 //***************************************************************************
39 // Constructor/Destructor
40 //***************************************************************************
41 
42 //---------------------------------------------------------------------------
CriticalSection()43 CriticalSection::CriticalSection()
44 {
45     CritSect=new wxCriticalSection();
46 }
47 
48 //---------------------------------------------------------------------------
~CriticalSection()49 CriticalSection::~CriticalSection()
50 {
51     delete ((wxCriticalSection*)CritSect); //CritSect=NULL;
52 }
53 
54 //***************************************************************************
55 // Enter/Leave
56 //***************************************************************************
57 
58 //---------------------------------------------------------------------------
Enter()59 void CriticalSection::Enter()
60 {
61     ((wxCriticalSection*)CritSect)->Enter();
62 }
63 
64 //---------------------------------------------------------------------------
Leave()65 void CriticalSection::Leave()
66 {
67     ((wxCriticalSection*)CritSect)->Leave();
68 }
69 
70 } //Namespace
71 
72 //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
73 //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
74 // WINDOWS
75 //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
76 //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
77 #else //ZENLIB_USEWX
78 #ifdef WINDOWS
79 //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
80 //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
81 
82 //---------------------------------------------------------------------------
83 #undef __TEXT
84 #include <windows.h>
85 //---------------------------------------------------------------------------
86 
87 
88 namespace ZenLib
89 {
90 
91 //***************************************************************************
92 // Constructor/Destructor
93 //***************************************************************************
94 
95 //---------------------------------------------------------------------------
CriticalSection()96 CriticalSection::CriticalSection()
97 {
98     CritSect=new CRITICAL_SECTION;
99     InitializeCriticalSection((CRITICAL_SECTION*)CritSect);
100 }
101 
102 //---------------------------------------------------------------------------
~CriticalSection()103 CriticalSection::~CriticalSection()
104 {
105     DeleteCriticalSection((CRITICAL_SECTION*)CritSect);
106     delete ((CRITICAL_SECTION*)CritSect); //CritSect=NULL;
107 }
108 
109 //***************************************************************************
110 // Enter/Leave
111 //***************************************************************************
112 
113 //---------------------------------------------------------------------------
Enter()114 void CriticalSection::Enter()
115 {
116     EnterCriticalSection((CRITICAL_SECTION*)CritSect);
117 }
118 
119 //---------------------------------------------------------------------------
Leave()120 void CriticalSection::Leave()
121 {
122     LeaveCriticalSection((CRITICAL_SECTION*)CritSect);
123 }
124 
125 } //Namespace
126 
127 //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
128 //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
129 // UNIX
130 //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
131 //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
132 #else //WINDOWS
133 //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
134 //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
135 
136 //---------------------------------------------------------------------------
137 #include <pthread.h>
138 //---------------------------------------------------------------------------
139 
140 namespace ZenLib
141 {
142 
143 //***************************************************************************
144 // Constructor/Destructor
145 //***************************************************************************
146 
147 //---------------------------------------------------------------------------
CriticalSection()148 CriticalSection::CriticalSection()
149 {
150     CritSect=new pthread_mutex_t;
151     pthread_mutex_init((pthread_mutex_t*)CritSect, NULL);
152 }
153 
154 //---------------------------------------------------------------------------
~CriticalSection()155 CriticalSection::~CriticalSection()
156 {
157     pthread_mutex_destroy((pthread_mutex_t*)CritSect);
158     delete (pthread_mutex_t*)CritSect;
159 }
160 
161 //***************************************************************************
162 // Enter/Leave
163 //***************************************************************************
164 
165 //---------------------------------------------------------------------------
Enter()166 void CriticalSection::Enter()
167 {
168     pthread_mutex_lock((pthread_mutex_t*)CritSect);
169 }
170 
171 //---------------------------------------------------------------------------
Leave()172 void CriticalSection::Leave()
173 {
174     pthread_mutex_unlock((pthread_mutex_t*)CritSect);
175 }
176 
177 } //Namespace
178 
179 //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
180 //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
181 //
182 //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
183 //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
184 #endif //WINDOWS
185 #endif //ZENLIB_USEWX
186 //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
187 //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
188