@@ -43,7 +43,7 @@ int _esodbc_log_level = LOG_LEVEL_DISABLED;
43
43
/* log file path -- process variable */
44
44
static TCHAR * log_path = NULL ;
45
45
/* log file mutex -- process variable */
46
- static HANDLE log_mux = NULL ;
46
+ static SRWLOCK log_mux = SRWLOCK_INIT ;
47
47
48
48
#define MUTEX_LOCK (_mux ) \
49
49
(WaitForSingleObject(_mux, INFINITE) == WAIT_OBJECT_0)
@@ -149,26 +149,12 @@ BOOL log_init()
149
149
150
150
/* save the file path and open the file, to check path validity */
151
151
log_path = path ;
152
- if (log_file_handle (/* open*/ TRUE) == INVALID_HANDLE_VALUE ) {
153
- return FALSE;
154
- }
155
-
156
- log_mux = CreateMutex (
157
- NULL , /* default security attributes */
158
- FALSE, /* initially not owned */
159
- NULL /* unnamed mutex */ );
160
- if (! log_mux ) {
161
- log_file_handle (/* close */ FALSE);
162
- return FALSE;
163
- }
164
- return TRUE;
152
+ return (log_file_handle (/* open*/ TRUE) != INVALID_HANDLE_VALUE );
165
153
}
166
154
167
155
void log_cleanup ()
168
156
{
169
- if (log_mux ) {
170
- CloseHandle (log_mux );
171
- }
157
+ /* There is no need/function to destroy the SRWLOCK */
172
158
log_file_handle (/* close */ FALSE);
173
159
174
160
}
@@ -276,10 +262,9 @@ static inline void log_file(int level, int werrno, const char *func,
276
262
pos += ret ;
277
263
assert (pos <= sizeof (buff ));
278
264
279
- if (MUTEX_LOCK (log_mux )) {
280
- log_file_write (buff , pos );
281
- MUTEX_UNLOCK (log_mux );
282
- }
265
+ AcquireSRWLockExclusive (& log_mux );
266
+ log_file_write (buff , pos );
267
+ ReleaseSRWLockExclusive (& log_mux );
283
268
}
284
269
285
270
void _esodbc_log (int lvl , int werrno , const char * func ,
0 commit comments