File tree Expand file tree Collapse file tree 1 file changed +21
-20
lines changed Expand file tree Collapse file tree 1 file changed +21
-20
lines changed Original file line number Diff line number Diff line change @@ -86,6 +86,9 @@ inline bool HxCreateDetachedThread(DWORD (WINAPI *func)(void *), void *param)
86
86
87
87
struct HxMutex
88
88
{
89
+ bool mValid ;
90
+ pthread_mutex_t *mMutex ;
91
+
89
92
HxMutex ()
90
93
{
91
94
pthread_mutexattr_t mta;
@@ -96,9 +99,7 @@ struct HxMutex
96
99
}
97
100
~HxMutex ()
98
101
{
99
- if (mValid )
100
- pthread_mutex_destroy (mMutex );
101
- delete mMutex ;
102
+ Clean ();
102
103
}
103
104
void Lock () { pthread_mutex_lock (mMutex ); }
104
105
void Unlock () { pthread_mutex_unlock (mMutex ); }
@@ -107,12 +108,16 @@ struct HxMutex
107
108
void Clean ()
108
109
{
109
110
if (mValid )
111
+ {
110
112
pthread_mutex_destroy (mMutex );
111
- mValid = 0 ;
113
+ mValid = false ;
114
+ }
115
+ if (mMutex )
116
+ {
117
+ delete mMutex ;
118
+ mMutex = nullptr ;
119
+ }
112
120
}
113
-
114
- bool mValid ;
115
- pthread_mutex_t *mMutex ;
116
121
};
117
122
118
123
#define THREAD_FUNC_TYPE void *
@@ -198,19 +203,20 @@ struct HxSemaphore
198
203
199
204
struct HxSemaphore
200
205
{
206
+ HxMutex mMutex ;
207
+ pthread_cond_t *mCondition ;
208
+ bool mSet ;
209
+
210
+
201
211
HxSemaphore ()
202
212
{
203
213
mSet = false ;
204
- mValid = true ;
205
214
mCondition = new pthread_cond_t ();
206
215
pthread_cond_init (mCondition ,0 );
207
216
}
208
217
~HxSemaphore ()
209
218
{
210
- if (mValid )
211
- {
212
- pthread_cond_destroy (mCondition );
213
- }
219
+ Clean ();
214
220
}
215
221
// For autolock
216
222
inline operator HxMutex &() { return mMutex ; }
@@ -294,19 +300,14 @@ struct HxSemaphore
294
300
void Clean ()
295
301
{
296
302
mMutex .Clean ();
297
- if (mValid )
303
+ if (mCondition )
298
304
{
299
- mValid = false ;
300
305
pthread_cond_destroy (mCondition );
306
+ delete mCondition ;
307
+ mCondition = nullptr ;
301
308
}
302
- delete mCondition ;
303
309
}
304
310
305
-
306
- HxMutex mMutex ;
307
- pthread_cond_t *mCondition ;
308
- bool mSet ;
309
- bool mValid ;
310
311
};
311
312
312
313
You can’t perform that action at this time.
0 commit comments