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 #include "pch.h"
30 #include "condvar.h"
31
32
33
34 UiCondVar* ui_condvar_create(
void) {
35 UiWinCondVar *var = new UiWinCondVar();
36 var->var.data =
NULL;
37 var->var.intdata =
0;
38 var->set =
0;
39 return (UiCondVar*)var;
40 }
41
42 void ui_condvar_wait(UiCondVar *var) {
43 UiWinCondVar *p = (UiWinCondVar*)var;
44 std::unique_lock<std::mutex> lock(p->mutex);
45
46 if(!p->set) {
47 p->cond.wait(lock);
48 }
49 p->set =
0;
50 }
51
52 void ui_condvar_signal(UiCondVar *var,
void *data,
int intdata) {
53 UiWinCondVar *p = (UiWinCondVar*)var;
54 std::unique_lock<std::mutex> lock(p->mutex);
55 p->var.data = data;
56 p->var.intdata = intdata;
57 p->set =
1;
58 lock.unlock();
59 p->cond.notify_one();
60 }
61
62 void ui_condvar_destroy(UiCondVar *var) {
63 UiWinCondVar *p = (UiWinCondVar*)var;
64 delete p;
65 }
66