forked from Matway/mpl-sl
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ConditionVariable.mpl
59 lines (48 loc) · 1.59 KB
/
ConditionVariable.mpl
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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
# Copyright (C) Matway Burkow
#
# This repository and all its contents belong to Matway Burkow (referred here and below as "the owner").
# The content is for demonstration purposes only.
# It is forbidden to use the content or any part of it for any purpose without explicit permission from the owner.
# By contributing to the repository, contributors acknowledge that ownership of their work transfers to the owner.
"String.printList" use
"control.Nat32" use
"control.exit" use
"control.when" use
"control.||" use
"kernel32.CONDITION_VARIABLE" use
"kernel32.ERROR_TIMEOUT" use
"kernel32.GetLastError" use
"kernel32.INFINITE" use
"kernel32.SleepConditionVariableSRW" use
"kernel32.WakeAllConditionVariable" use
"kernel32.WakeConditionVariable" use
ConditionVariable: [{
SCHEMA_NAME: "ConditionVariable" virtual;
DIE: [
];
INIT: [
0nx @conditionVariable.!Ptr
];
wait: [
srwLock: time: shared:;;;
shared [CONDITION_VARIABLE_LOCKMODE_SHARED] [0n32] if
time -1 = [INFINITE] [time Nat32 cast] if
@srwLock.@srwLock
@conditionVariable
SleepConditionVariableSRW 1 = [TRUE] [
error: GetLastError;
error ERROR_TIMEOUT = ~ [time -1 =] || [
("SleepConditionVariableSRW failed, result=" error LF) printList 1 exit # There is no good way to handle this, report and abort
] when
FALSE
] if
];
wakeAll: [
@conditionVariable WakeAllConditionVariable
];
wakeOne: [
@conditionVariable WakeConditionVariable
];
# Private
conditionVariable: CONDITION_VARIABLE;
}];