-
Notifications
You must be signed in to change notification settings - Fork 20
Expand file tree
/
Copy pathulog_lock_win.c
More file actions
38 lines (34 loc) · 1.13 KB
/
ulog_lock_win.c
File metadata and controls
38 lines (34 loc) · 1.13 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
// *************************************************************************
// microlog extension: Windows Critical Section lock helper (implementation)
// *************************************************************************
#include "ulog_lock_win.h"
#include <stddef.h>
#include <synchapi.h>
#include "ulog.h"
// Internal lock function ----------------------------------------------------
/** @brief Internal lock adapter for Windows Critical Section. */
static ulog_status win_lock_fn(bool lock, void *arg) {
if (arg == NULL) {
return ULOG_STATUS_INVALID_ARGUMENT;
}
CRITICAL_SECTION *cs = (CRITICAL_SECTION *)arg;
if (lock) {
EnterCriticalSection(cs);
} else {
LeaveCriticalSection(cs);
}
return ULOG_STATUS_OK;
}
/** @copydoc ulog_lock_win_enable */
ulog_status ulog_lock_win_enable(CRITICAL_SECTION *cs) {
if (cs == NULL) {
return ULOG_STATUS_INVALID_ARGUMENT;
}
ulog_lock_set_fn(win_lock_fn, cs);
return ULOG_STATUS_OK;
}
/** @copydoc ulog_lock_win_disable */
ulog_status ulog_lock_win_disable(void) {
ulog_lock_set_fn(NULL, NULL);
return ULOG_STATUS_OK;
}