Skip to content

Commit

Permalink
It turns out that darwin returns ENOSYS on sem_init.
Browse files Browse the repository at this point in the history
Switch implementation to mutex + cond-variable for python, which
should hopefully work everywhere.
  • Loading branch information
andreilitvin committed Nov 10, 2023
1 parent f06d952 commit bd77940
Showing 1 changed file with 16 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@
#include "ChipMainLoopWork.h"

#include <platform/CHIPDeviceLayer.h>
#include <semaphore.h>
#include <mutex>
#include <condition_variable>

namespace chip {
namespace MainLoopWork {
Expand All @@ -27,12 +28,21 @@ namespace {
struct WorkData
{
std::function<void()> 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)
Expand Down

0 comments on commit bd77940

Please sign in to comment.