Wed, 30 Oct 2024 15:32:38 +0100
fix condvar windows implementation
ui/winui/condvar.cpp | file | annotate | diff | comparison | revisions | |
ui/winui/condvar.h | file | annotate | diff | comparison | revisions |
--- a/ui/winui/condvar.cpp Wed Oct 30 15:15:36 2024 +0100 +++ b/ui/winui/condvar.cpp Wed Oct 30 15:32:38 2024 +0100 @@ -32,7 +32,7 @@ UiCondVar* ui_condvar_create(void) { - UiWinCondVar *var = (UiWinCondVar*)malloc(sizeof(UiWinCondVar)); + UiWinCondVar *var = new UiWinCondVar(); var->var.data = NULL; var->var.intdata = 0; var->set = 0; @@ -41,28 +41,25 @@ void ui_condvar_wait(UiCondVar *var) { UiWinCondVar *p = (UiWinCondVar*)var; - p->mutex.lock(); + std::unique_lock<std::mutex> lock(p->mutex); + if(!p->set) { - std::unique_lock<std::mutex> lock(p->mutex); p->cond.wait(lock); } p->set = 0; - p->mutex.unlock(); - } void ui_condvar_signal(UiCondVar *var, void *data, int intdata) { UiWinCondVar *p = (UiWinCondVar*)var; - p->mutex.lock(); + 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(); - p->mutex.unlock(); } void ui_condvar_destroy(UiCondVar *var) { UiWinCondVar *p = (UiWinCondVar*)var; - free(p); - + delete p; }
--- a/ui/winui/condvar.h Wed Oct 30 15:15:36 2024 +0100 +++ b/ui/winui/condvar.h Wed Oct 30 15:32:38 2024 +0100 @@ -39,12 +39,12 @@ extern "C" { #endif -typedef struct UiWinCondVar { +struct UiWinCondVar { UiCondVar var; int set; std::mutex mutex; std::condition_variable cond; -} UiWinCondVar; +}; #ifdef __cplusplus