ui/winui/condvar.cpp

branch
newapi
changeset 376
5578494147cb
parent 373
2eede3d98aba
--- 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;
 }

mercurial