forked from xiaozhi/xiaozhi-esp32
新的opus封装以及优化const会导致的内存拷贝
This commit is contained in:
@@ -31,12 +31,16 @@ void BackgroundTask::Schedule(std::function<void()> callback) {
|
||||
ESP_LOGW(TAG, "active_tasks_ == %u", active_tasks_.load());
|
||||
}
|
||||
active_tasks_++;
|
||||
auto wrapped_callback = [this, callback]() {
|
||||
callback();
|
||||
active_tasks_--;
|
||||
condition_variable_.notify_all();
|
||||
};
|
||||
main_tasks_.push_back(wrapped_callback);
|
||||
main_tasks_.emplace_back([this, cb = std::move(callback)]() {
|
||||
cb();
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(mutex_);
|
||||
active_tasks_--;
|
||||
if (main_tasks_.empty() && active_tasks_ == 0) {
|
||||
condition_variable_.notify_all();
|
||||
}
|
||||
}
|
||||
});
|
||||
condition_variable_.notify_all();
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user