#include "pch.h"
#include "condvar.h"
UiCondVar* ui_condvar_create(
void) {
UiWinCondVar *var = new UiWinCondVar();
var->var.data =
NULL;
var->var.intdata =
0;
var->set =
0;
return (UiCondVar*)var;
}
void ui_condvar_wait(UiCondVar *var) {
UiWinCondVar *p = (UiWinCondVar*)var;
std::unique_lock<std::mutex> lock(p->mutex);
if(!p->set) {
p->cond.wait(lock);
}
p->set =
0;
}
void ui_condvar_signal(UiCondVar *var,
void *data,
int intdata) {
UiWinCondVar *p = (UiWinCondVar*)var;
std::unique_lock<std::mutex> lock(p->mutex);
p->var.data = data;
p->var.intdata = intdata;
p->set =
1;
lock.unlock();
p->cond.notify_one();
}
void ui_condvar_destroy(UiCondVar *var) {
UiWinCondVar *p = (UiWinCondVar*)var;
delete p;
}