Skip to content

Commit

Permalink
Also fix java
Browse files Browse the repository at this point in the history
  • Loading branch information
andreilitvin committed Nov 10, 2023
1 parent b1669c0 commit 9c9da0a
Showing 1 changed file with 19 additions and 6 deletions.
25 changes: 19 additions & 6 deletions src/app/server/java/ChipThreadWork.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@

#include "ChipThreadWork.h"
#include <platform/CHIPDeviceLayer.h>
#include <semaphore.h>

#include <condition_variable>
#include <mutex>

namespace chip {
namespace ThreadWork {
Expand All @@ -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)
Expand Down

0 comments on commit 9c9da0a

Please sign in to comment.