feat(examples): Add support for lwip build under linux

This commit is contained in:
David Cermak
2023-04-04 12:57:38 +02:00
parent c443326a34
commit 588465d9db
12 changed files with 56 additions and 21 deletions

View File

@ -0,0 +1,57 @@
/*
* SPDX-FileCopyrightText: 2021-2022 Espressif Systems (Shanghai) CO LTD
*
* SPDX-License-Identifier: Apache-2.0
*/
#pragma once
#include <queue>
#include <mutex>
#include <condition_variable>
#include <memory>
#include <thread>
#include <atomic>
typedef void (*cb_t)(void *arg);
class TimerTaskMock {
public:
TimerTaskMock(cb_t cb): cb(cb), active(false), ms(INT32_MAX) {}
~TimerTaskMock(void)
{
active = false;
t.join();
}
void SetTimeout(uint32_t m)
{
ms = m;
active = true;
t = std::thread(run_static, this);
}
private:
static void run_static(TimerTaskMock *timer)
{
timer->run();
}
void run(void)
{
while (!active.load()) {
std::this_thread::sleep_for(std::chrono::milliseconds(1));
}
while (active.load()) {
std::this_thread::sleep_for(std::chrono::milliseconds(ms));
cb(nullptr);
}
}
cb_t cb;
std::thread t;
std::atomic<bool> active;
uint32_t ms;
};