Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make ChipMainLoopWork_WorkSchedule.cpp work on darwin #30425

Merged
merged 5 commits into from
Nov 13, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 17 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,21 @@ 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); }
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
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,9 @@
*/
#include "ChipMainLoopWork.h"

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

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); }
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
2 changes: 1 addition & 1 deletion third_party/mbedtls/repo
Submodule repo updated from e44be6 to d6d43e
2 changes: 1 addition & 1 deletion third_party/pigweed/repo
Submodule repo updated 333 files
Loading