Open
como quitar bing de firefox
Todas las respuestas (1)
- include <queue>
- include <mutex>
- include <condition_variable>
- include <functional>
// Pipeline stage genérico template<typename T> class TunnelStage {
std::queue<T> queue; std::mutex mtx; std::condition_variable cv; std::function<T(T)> process_fn; bool updated = false;
public:
TunnelStage(std::function<T(T)> fn) : process_fn(fn) {}
void updateFunction(std::function<T(T)> new_fn) {
std::lock_guard<std::mutex> lock(mtx);
process_fn = new_fn;
updated = true;
cv.notify_all();
}
void push(T data) {
std::lock_guard<std::mutex> lock(mtx);
queue.push(data);
cv.notify_one();
}
T run(T input) {
std::unique_lock<std::mutex> lock(mtx);
cv.wait(lock, [this]{ return!queue.empty() || updated; });
updated = false;
return process_fn(input);
}
};
// Uso: actualizar lógica del túnel en runtime TunnelStage<int> stage1([](int x){ return x * 2; });
// En otro thread, para hacer update sin parar pipeline: stage1.updateFunction([](int x){ return x * 3 + 1; }); // nueva lógica