feat(furvm): introduce executor
This commit is contained in:
@@ -13,8 +13,10 @@ namespace furvm {
|
||||
class context {
|
||||
public:
|
||||
using value_type = std::unique_ptr<mod>; /**< An alias to unique pointer of module. */
|
||||
|
||||
friend class executor;
|
||||
public:
|
||||
context() = default;
|
||||
context();
|
||||
~context() = default;
|
||||
|
||||
/**
|
||||
@@ -92,7 +94,8 @@ public:
|
||||
*/
|
||||
constexpr size_t size() const { return m_modules.size(); }
|
||||
private:
|
||||
std::vector<std::unique_ptr<mod>> m_modules;
|
||||
std::vector<std::unique_ptr<mod>> m_modules;
|
||||
std::vector<std::shared_ptr<executor>> m_executors;
|
||||
};
|
||||
|
||||
} // namespace furvm
|
||||
|
||||
@@ -0,0 +1,88 @@
|
||||
#ifndef FURVM_EXECUTOR_HPP
|
||||
#define FURVM_EXECUTOR_HPP
|
||||
|
||||
#include "furvm/fwd.hpp"
|
||||
|
||||
#include <memory>
|
||||
|
||||
namespace furvm {
|
||||
|
||||
enum class executor_flags : std::uint32_t {
|
||||
Suspended = (1 << 0), /**< Execution suspended. */
|
||||
};
|
||||
|
||||
static inline executor_flags operator|(executor_flags lhs, executor_flags rhs) {
|
||||
return executor_flags(static_cast<std::uint32_t>(lhs) | static_cast<std::uint32_t>(rhs));
|
||||
}
|
||||
|
||||
static inline executor_flags operator&(executor_flags lhs, executor_flags rhs) {
|
||||
return executor_flags(static_cast<std::uint32_t>(lhs) & static_cast<std::uint32_t>(rhs));
|
||||
}
|
||||
|
||||
static inline executor_flags operator~(executor_flags flags) {
|
||||
return executor_flags(~static_cast<std::uint32_t>(flags));
|
||||
}
|
||||
|
||||
class executor {
|
||||
private:
|
||||
/**
|
||||
* @brief A private token for the private constructor.
|
||||
*
|
||||
* Also `egzekutor` in Polish translates to `executor` I think.
|
||||
*/
|
||||
struct egzekutor {
|
||||
explicit egzekutor() = default;
|
||||
};
|
||||
public:
|
||||
/**
|
||||
* @brief Private constructor.
|
||||
*
|
||||
* @param id
|
||||
* @param context
|
||||
*/
|
||||
executor(egzekutor, executor_handle id, const std::shared_ptr<context>& context);
|
||||
|
||||
~executor();
|
||||
|
||||
/**
|
||||
* @brief Move constructor.
|
||||
*/
|
||||
executor(executor&&) = default;
|
||||
|
||||
/**
|
||||
* @brief Move constructor.
|
||||
*/
|
||||
executor& operator=(executor&&) = default;
|
||||
|
||||
executor(const executor&) = delete;
|
||||
executor& operator=(const executor&) = delete;
|
||||
public:
|
||||
/**
|
||||
* @brief Returns a new executor.
|
||||
*
|
||||
* @param context Furvm context.
|
||||
*/
|
||||
static std::shared_ptr<executor> create(const std::shared_ptr<context>& context);
|
||||
public:
|
||||
/**
|
||||
* @brief Returns an id of this executor.
|
||||
*
|
||||
* @return The id.
|
||||
*/
|
||||
executor_handle id() const { return m_id; }
|
||||
|
||||
/**
|
||||
* @brief Returns flags of this executor.
|
||||
*
|
||||
* @return The flags.
|
||||
*/
|
||||
executor_flags flags() const { return m_flags; }
|
||||
private:
|
||||
executor_handle m_id;
|
||||
executor_flags m_flags{}; // NOLINT(bugprone-invalid-enum-default-initialization)
|
||||
std::shared_ptr<context> m_context;
|
||||
};
|
||||
|
||||
} // namespace furvm
|
||||
|
||||
#endif // FURVM_EXECUTOR_HPP
|
||||
@@ -61,6 +61,27 @@ class mod;
|
||||
*/
|
||||
using module_handle = std::uint32_t;
|
||||
|
||||
// executor.hpp
|
||||
|
||||
/**
|
||||
* @enum executor_flags
|
||||
* @brief Flags of an executor.
|
||||
*/
|
||||
enum class executor_flags : std::uint32_t;
|
||||
|
||||
/**
|
||||
* @class executor
|
||||
* @brief Furvm executor.
|
||||
*
|
||||
* Furvm executors are like threads.
|
||||
*/
|
||||
class executor;
|
||||
|
||||
/**
|
||||
* @brief Furvm executor's index.
|
||||
*/
|
||||
using executor_handle = std::uint32_t;
|
||||
|
||||
// context.hpp
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user