From bd779400a8cb5a138fc125aff3895d20b196d89f Mon Sep 17 00:00:00 2001 From: Andrei Litvin Date: Fri, 10 Nov 2023 16:41:49 -0500 Subject: [PATCH 1/4] It turns out that darwin returns ENOSYS on sem_init. Switch implementation to mutex + cond-variable for python, which should hopefully work everywhere. --- .../native/ChipMainLoopWork_WorkSchedule.cpp | 22 ++++++++++++++----- 1 file changed, 16 insertions(+), 6 deletions(-) diff --git a/src/controller/python/chip/native/ChipMainLoopWork_WorkSchedule.cpp b/src/controller/python/chip/native/ChipMainLoopWork_WorkSchedule.cpp index fec65a150c9396..24131090aac5b8 100644 --- a/src/controller/python/chip/native/ChipMainLoopWork_WorkSchedule.cpp +++ b/src/controller/python/chip/native/ChipMainLoopWork_WorkSchedule.cpp @@ -18,7 +18,8 @@ #include "ChipMainLoopWork.h" #include -#include +#include +#include namespace chip { namespace MainLoopWork { @@ -27,12 +28,21 @@ namespace { struct WorkData { std::function 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) From b1669c092fc97e982ca92d4ab3e4f93e861dfba0 Mon Sep 17 00:00:00 2001 From: Andrei Litvin Date: Fri, 10 Nov 2023 16:42:37 -0500 Subject: [PATCH 2/4] restyle --- .../chip/native/ChipMainLoopWork_WorkSchedule.cpp | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/controller/python/chip/native/ChipMainLoopWork_WorkSchedule.cpp b/src/controller/python/chip/native/ChipMainLoopWork_WorkSchedule.cpp index 24131090aac5b8..e52532f3f4f4ac 100644 --- a/src/controller/python/chip/native/ChipMainLoopWork_WorkSchedule.cpp +++ b/src/controller/python/chip/native/ChipMainLoopWork_WorkSchedule.cpp @@ -17,9 +17,9 @@ */ #include "ChipMainLoopWork.h" -#include -#include #include +#include +#include namespace chip { namespace MainLoopWork { @@ -34,12 +34,14 @@ struct WorkData WorkData() {} ~WorkData() {} - void Post() { + void Post() + { std::unique_lock lock(mux); done = true; cond.notify_all(); } - void Wait() { + void Wait() + { std::unique_lock lock(mux); cond.wait(lock, [&] { return done; }); } From 9c9da0a16fecd0004a726c2a373d2979d5f0a22c Mon Sep 17 00:00:00 2001 From: Andrei Litvin Date: Fri, 10 Nov 2023 16:48:46 -0500 Subject: [PATCH 3/4] 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) From 1abd3bd5f08573f68e84c60d32ad699b87dd8f0b Mon Sep 17 00:00:00 2001 From: Andrei Litvin Date: Mon, 13 Nov 2023 10:42:58 -0500 Subject: [PATCH 4/4] Remove empty constructor/destructor --- src/app/server/java/ChipThreadWork.cpp | 2 -- .../python/chip/native/ChipMainLoopWork_WorkSchedule.cpp | 2 -- third_party/imgui/repo | 2 +- third_party/mbedtls/repo | 2 +- third_party/nanopb/repo | 2 +- third_party/pigweed/repo | 2 +- 6 files changed, 4 insertions(+), 8 deletions(-) diff --git a/src/app/server/java/ChipThreadWork.cpp b/src/app/server/java/ChipThreadWork.cpp index 7da13c396b046a..c95fd647ee1de4 100644 --- a/src/app/server/java/ChipThreadWork.cpp +++ b/src/app/server/java/ChipThreadWork.cpp @@ -32,8 +32,6 @@ struct WorkData std::condition_variable cond; bool done = false; - WorkData() {} - ~WorkData() {} void Post() { std::unique_lock lock(mux); diff --git a/src/controller/python/chip/native/ChipMainLoopWork_WorkSchedule.cpp b/src/controller/python/chip/native/ChipMainLoopWork_WorkSchedule.cpp index e52532f3f4f4ac..7abf1d9f81a92c 100644 --- a/src/controller/python/chip/native/ChipMainLoopWork_WorkSchedule.cpp +++ b/src/controller/python/chip/native/ChipMainLoopWork_WorkSchedule.cpp @@ -32,8 +32,6 @@ struct WorkData std::condition_variable cond; bool done = false; - WorkData() {} - ~WorkData() {} void Post() { std::unique_lock lock(mux); diff --git a/third_party/imgui/repo b/third_party/imgui/repo index 454f36d2af9d92..1ab63d925f21e0 160000 --- a/third_party/imgui/repo +++ b/third_party/imgui/repo @@ -1 +1 @@ -Subproject commit 454f36d2af9d92a0f8ffe8536c218247df732edc +Subproject commit 1ab63d925f21e03be7735661500e5b914dd93c19 diff --git a/third_party/mbedtls/repo b/third_party/mbedtls/repo index e44be6a7d3d31f..d6d43ec8a59f5f 160000 --- a/third_party/mbedtls/repo +++ b/third_party/mbedtls/repo @@ -1 +1 @@ -Subproject commit e44be6a7d3d31f3fac1a74b262b395984d193b05 +Subproject commit d6d43ec8a59f5f5dc1a2138fe57dacea31736e94 diff --git a/third_party/nanopb/repo b/third_party/nanopb/repo index 9aa922d9dbaf14..9766c4589f61b7 160000 --- a/third_party/nanopb/repo +++ b/third_party/nanopb/repo @@ -1 +1 @@ -Subproject commit 9aa922d9dbaf147b07cc0fdb2392a9995c4e95db +Subproject commit 9766c4589f61b76807a0a394040c15a2d23ef24c diff --git a/third_party/pigweed/repo b/third_party/pigweed/repo index 5eccd87a773568..90d97fa3b4292c 160000 --- a/third_party/pigweed/repo +++ b/third_party/pigweed/repo @@ -1 +1 @@ -Subproject commit 5eccd87a773568f5db5f5e7f1dd0809860f3d01e +Subproject commit 90d97fa3b4292c39074e6f2b94dbd1cffa6ee318