From 9c9da0a16fecd0004a726c2a373d2979d5f0a22c Mon Sep 17 00:00:00 2001 From: Andrei Litvin Date: Fri, 10 Nov 2023 16:48:46 -0500 Subject: [PATCH] Also fix java --- src/app/server/java/ChipThreadWork.cpp | 25 +++++++++++++++++++------ 1 file changed, 19 insertions(+), 6 deletions(-) diff --git a/src/app/server/java/ChipThreadWork.cpp b/src/app/server/java/ChipThreadWork.cpp index 334e3052211e42..7da13c396b046a 100644 --- a/src/app/server/java/ChipThreadWork.cpp +++ b/src/app/server/java/ChipThreadWork.cpp @@ -17,7 +17,9 @@ #include "ChipThreadWork.h" #include -#include + +#include +#include namespace chip { namespace ThreadWork { @@ -26,12 +28,23 @@ namespace { struct WorkData { WorkCallback callback; - sem_t done; + std::mutex mux; + std::condition_variable cond; + bool done = false; - WorkData() { sem_init(&done, 0 /* shared */, 0); } - ~WorkData() { sem_destroy(&done); } - void Post() { sem_post(&done); } - void Wait() { sem_wait(&done); } + WorkData() {} + ~WorkData() {} + void Post() + { + std::unique_lock lock(mux); + done = true; + cond.notify_all(); + } + void Wait() + { + std::unique_lock lock(mux); + cond.wait(lock, [&] { return done; }); + } }; void PerformWork(intptr_t arg)