forked from xiaozhi/xiaozhi-esp32
fit the memory usage for esp32c3
This commit is contained in:
33
main/background_task.h
Normal file
33
main/background_task.h
Normal file
@@ -0,0 +1,33 @@
|
||||
#ifndef BACKGROUND_TASK_H
|
||||
#define BACKGROUND_TASK_H
|
||||
|
||||
#include <freertos/FreeRTOS.h>
|
||||
#include <freertos/task.h>
|
||||
#include <mutex>
|
||||
#include <list>
|
||||
#include <condition_variable>
|
||||
#include <atomic>
|
||||
|
||||
class BackgroundTask {
|
||||
public:
|
||||
BackgroundTask(uint32_t stack_size = 4096 * 2);
|
||||
~BackgroundTask();
|
||||
|
||||
void Schedule(std::function<void()> callback);
|
||||
void WaitForCompletion();
|
||||
|
||||
private:
|
||||
std::mutex mutex_;
|
||||
std::list<std::function<void()>> main_tasks_;
|
||||
std::condition_variable condition_variable_;
|
||||
TaskHandle_t background_task_handle_ = nullptr;
|
||||
std::atomic<size_t> active_tasks_{0};
|
||||
|
||||
TaskHandle_t task_ = nullptr;
|
||||
StaticTask_t task_buffer_;
|
||||
StackType_t* task_stack_ = nullptr;
|
||||
|
||||
void BackgroundTaskLoop();
|
||||
};
|
||||
|
||||
#endif
|
||||
Reference in New Issue
Block a user