Skip to content

Commit 54746b9

Browse files
committed
switch to SRWLOCK locks for logging
1 parent 9d942ab commit 54746b9

File tree

1 file changed

+6
-21
lines changed

1 file changed

+6
-21
lines changed

driver/log.c

Lines changed: 6 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ int _esodbc_log_level = LOG_LEVEL_DISABLED;
4343
/* log file path -- process variable */
4444
static TCHAR *log_path = NULL;
4545
/* log file mutex -- process variable */
46-
static HANDLE log_mux = NULL;
46+
static SRWLOCK log_mux = SRWLOCK_INIT;
4747

4848
#define MUTEX_LOCK(_mux) \
4949
(WaitForSingleObject(_mux, INFINITE) == WAIT_OBJECT_0)
@@ -149,26 +149,12 @@ BOOL log_init()
149149

150150
/* save the file path and open the file, to check path validity */
151151
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);
165153
}
166154

167155
void log_cleanup()
168156
{
169-
if (log_mux) {
170-
CloseHandle(log_mux);
171-
}
157+
/* There is no need/function to destroy the SRWLOCK */
172158
log_file_handle(/* close */FALSE);
173159

174160
}
@@ -276,10 +262,9 @@ static inline void log_file(int level, int werrno, const char *func,
276262
pos += ret;
277263
assert(pos <= sizeof(buff));
278264

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);
283268
}
284269

285270
void _esodbc_log(int lvl, int werrno, const char *func,

0 commit comments

Comments
 (0)