Files
EVEngine/src/modules/thread/Task.h
T
西风逍遥游 4377e062dd feat: zeroerr parameter validation + Doxygen API documentation
Squashed onto current main. Adds src/engine/common/Assert.h (EV_PARAM_CHECK / EV_ASSERT backed by zeroerr), an EVENGINE_ENABLE_ASSERTS option (non-Debug builds strip ZEROERR_NO_ASSERT unless enabled), parameter checks at key entry points, Doxygen comments across headers, Doxyfile + make docs / CMake docs targets, and Windows setup + code conventions in AGENTS.md.
2026-08-19 09:01:12 +08:00

53 lines
1.1 KiB
C++

#pragma once
#include <condition_variable>
#include <functional>
#include <memory>
#include <mutex>
#include <string>
namespace eve {
namespace thread {
/**
* @brief A job executed by a ThreadPool worker.
* Status strings (no enums): "pending" | "running" | "done" | "failed".
*/
class Task {
public:
explicit Task(std::function<void()> fn);
~Task();
std::string getStatus() const;
bool isDone() const;
bool hasFailed() const;
std::string getError() const;
/** @brief Block until the task finishes (done or failed). */
void wait();
// Internal — called by ThreadPool workers.
void run();
private:
struct State {
explicit State(std::function<void()> taskFn) : fn(std::move(taskFn)) {}
std::function<void()> fn;
mutable std::mutex mu;
std::condition_variable cv;
std::string status = "pending";
std::string error;
};
explicit Task(std::shared_ptr<State> state);
static void run(const std::shared_ptr<State> &state);
std::shared_ptr<State> state_;
friend class ThreadPool;
};
} // namespace thread
} // namespace eve